IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Composants Semi-Transparent -TGroupBox TButton etc


Sujet :

Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    249
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Août 2006
    Messages : 249
    Par défaut Composants Semi-Transparent -TGroupBox TButton etc
    Bonjour,

    J'aimerais avoir des composants semi-transparents avec Delphi 6 pour Win. Est-ce possible ? Pour les bitmaps ca va on a accès à l'alphablend. L'idéal serait de pouvoir créer un TGroupBox semi-transparent et quand j'ajoute des composants à l'intérieur les composants héritent de la semi-transparence aussi.

    J'avais pensé extraire le bitmap du composant par son canevas, modifier le bitmap et le réécrire dans son canevas.

    Merci.
    Pipo123

  2. #2
    Modérateur

    Homme Profil pro
    Ingénieur retraité
    Inscrit en
    Octobre 2005
    Messages
    2 396
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur retraité

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 396
    Par défaut
    J'allais juste arrêter ma session sur le Forum.
    Voiçi un bout de code qui peut éventuellement te donner des idées pour l'adapter à la semi-transparence d'un composant puisque ce code vise l'ensemble de la Form. Il s'agit d'un copier-coller que j'ai mis dans mon pense-bête pour le cas où, un jour où j'ai fait du lèche-vitrine sur internet. Comme je ne l'ai pas encore testé il n'a pas encore transité par l'éditeur de Delphi ceci explique la perte de l'indentation.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    ...make a Form semi-/ transparent?	
    Author: Lars Pietrowski 	
    [ Print tip ]			
     
    Tip Rating (38):		
     
    // Make your forms 25%, 50% Transparent...
     
    TMyForm = class (TForm);
     
    TrackBar1: TTrackBar;
    //..
    private
    FColorKey: TCOLOR;
     
    end;
     
    const
    // Use crKey as the transparency color.
    LWA_COLORKEY = 1;
    // Use bAlpha to determine the opacity of the layered window..
    LWA_ALPHA = 2;
    WS_EX_LAYERED = $80000;
     
    implementation
     
    {$R *.DFM}
     
    // The SetLayeredWindowAttributes function sets the opacity and transparency
    // color key of a layered window.
    // Note : This function is only available with Windows 2000 and XP!
    function SetLayeredWindowAttributes(
    // Handle to the layered window.
    Wnd: hwnd;
    // Pointer to a COLORREF value that specifies the transparency
    // color key to be used when composing the layered window
    crKey: ColorRef;
    // Alpha value used to describe the opacity of the layered window
    Alpha: Byte;
    // Specifies an action to take
    // LWA_COLORKEY or LWA_ALPHA
    // This parameter can be one or more of the following values:
    dwFlags: DWORD): Boolean;
    stdcall; external 'user32.dll';
     
     
    procedure TMyForm.TrackBar1Change(Sender: TObject);
    // Trackbar.Position must run at range 1-255...
    begin
    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
    SetLayeredWindowAttributes(Handle, ColorToRGB(FColorKey), TrackBar1.Position, LWA_ALPHA);
    end;
     
    {******************************************************************}
     
    { To load the SetLayeredWindowAttributes() function dynamically, use this function:}
     
    function MakeWindowTransparent(Wnd: HWND; nAlpha: Integer = 10): Boolean;
    type
    TSetLayeredWindowAttributes = function(hwnd: HWND; crKey: COLORREF; bAlpha: Byte;
    dwFlags: Longint): Longint; 
    stdcall;
    const
    // Use crKey as the transparency color.
    LWA_COLORKEY = 1;
    // Use bAlpha to determine the opacity of the layered window..
    LWA_ALPHA = 2;
    WS_EX_LAYERED = $80000;
    var
    hUser32: HMODULE;
    SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
    i: Integer;
    begin
    Result := False;
    // Here we import the function from USER32.DLL
    hUser32 := GetModuleHandle('USER32.DLL');
    if hUser32 <> 0 then
    begin @SetLayeredWindowAttributes := GetProcAddress(hUser32, 'SetLayeredWindowAttributes');
    // If the import did not succeed, make sure your app can handle it!
    if @SetLayeredWindowAttributes <> nil then
    begin
    // Check the current state of the dialog, and then add the WS_EX_LAYERED attribute
    SetWindowLong(Wnd, GWL_EXSTYLE, GetWindowLong(Wnd, GWL_EXSTYLE) or WS_EX_LAYERED);
    // The SetLayeredWindowAttributes function sets the opacity and
    // transparency color key of a layered window
    SetLayeredWindowAttributes(Wnd, 0, Trunc((255 / 100) * (100 - nAlpha)), LWA_ALPHA);
    Result := True;
    end;
    end;
    end;
    N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

Discussions similaires

  1. List semi transparent
    Par ticain dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 23/08/2006, 20h23
  2. [VB6]Semi-transparence pour les imageboxes ou usercontrols
    Par BrianDarkfield dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 06/05/2006, 21h35
  3. Composant graphic "transparent" aux événements sou
    Par jmborbe dans le forum Composants VCL
    Réponses: 5
    Dernier message: 04/11/2005, 17h17
  4. [Composant] Panel transparent paramétré
    Par Pedro dans le forum Composants VCL
    Réponses: 2
    Dernier message: 08/10/2005, 18h43
  5. [Composant] La transparence
    Par Nuts07 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 22/05/2003, 14h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo