Les Snippets

Connexion

Rendre une form transparente / translucide

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 12/01/2010 14:31:58 et initié par PCPT [Liste]
Vue : 14646
Catégorie(s) : API, Trucs & Astuces, Graphique
Langages dispo pour ce code :
- VB6
- VBA
- VB 2005, VB 2008
- C# 2.x, C# 3.x



Langage : VB6
Date ajout : 12/01/2010
Posté par PCPT [Liste]
Private Const GWL_EXSTYLE As Long = (-20)
Private Const LWA_ALPHA As Long &H2
Private Const WS_EX_LAYERED As Long &H80000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongByVal nIndex As Long) As  Long
Private Declare Function SetLayeredWindowAttributes Lib  "user32" (ByVal hwnd As LongByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As  Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongByVal nIndex As Long, ByVal dwNewLong As Long) As  Long
        
Public Sub SetFormTransparence(ByVal lHwnd As Long, ByVal bTransparent As Boolean)
    Dim lStyle As Long
    lStyle = GetWindowLong(lHwnd, GWL_EXSTYLE)
    If lStyle <> (lStyle Or WS_EX_LAYERED) Then Call SetWindowLong(lHwnd,  GWL_EXSTYLE, lStyle Or WS_EX_LAYERED)
    
    Call SetLayeredWindowAttributes(lHwnd,  0&, IIf(bTransparent, 127, 255), LWA_ALPHA)
End Sub

Remarque :
code présent un peu partout sur la toile
ici on active ou désactive la transparence en une ligne
valable à partir de windows 2000
Langage : VBA
Date ajout : 12/01/2010
Posté par PCPT [Liste]
Private Const GWL_EXSTYLE As Long = (-20)
Private Const LWA_ALPHA As Long &H2
Private Const WS_EX_LAYERED As Long &H80000
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As StringByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongByVal nIndex As Long) As  Long
Private Declare Function SetLayeredWindowAttributes Lib  "user32" (ByVal hwnd As LongByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As  Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongByVal nIndex As Long, ByVal dwNewLong As Long) As  Long
Public Sub SetFormTransparence(ByVal sUserformCaption As String, ByVal bTransparent As Boolean)
    Dim lHwnd  As Long
    Dim lStyle As Long
    lHwnd = FindWindowA("Thunder" IIf(Application.Version Like "8*""X""D") & "Frame", sUserformCaption)
    If lHwnd <> Then
        lStyle = GetWindowLong(lHwnd, GWL_EXSTYLE)
        If lStyle <> (lStyle Or WS_EX_LAYERED) Then Call SetWindowLong(lHwnd,  GWL_EXSTYLE, lStyle Or WS_EX_LAYERED)
        
        Call SetLayeredWindowAttributes(lHwnd,  0&, IIf(bTransparent, 127, 255), LWA_ALPHA)
    End If
End Sub
Remarque :
applicable depuis le caption du userform
toujours à partir de windows 2000
Langage : VB 2005 , VB 2008
Date ajout : 12/01/2010
Posté par PCPT [Liste]
Public Sub SetFormTransparence(ByRef frm As System.Windows.Forms.Form, ByVal bTransparent As Boolean)
    If bTransparent Then frm.Opacity = 0.5# Else frm.Opacity = 1.0#
End Sub
Langage : C# 2.x , C# 3.x
Date ajout : 12/01/2010
Posté par PCPT [Liste]
public void SetFormTransparence(System.Windows.Forms.Form frm, Boolean bTransparent)
{
    frm.Opacity = (bTransparent == true ? 0.5 : 1);
}

Snippets en rapport avec : Form, Alpha, Transparente, Translucide



Codes sources en rapport avec : Form, Alpha, Transparente, Translucide

{Visual Basic, VB6, VB.NET, VB 2005} ENCORE UNE FORM AEROGLASS SANS API AVEC EFFET FLOU
Voila c'est un composant à glisser dans une form pour la transformer en aeroglass. le code est en p...

{C / C++ / C++.NET} DESSINER UNE IMAGE TRANSPARENTE (WIN32)
Ce code montre comment dessiner une image avec de la transparence, mais de manière non uniforme (les...

{Visual Basic, VB6, VB.NET, VB 2005} FORM TRANSPARENTE
Voila une Form rendu transparente grâce à une capture d'écran projetée en background : bon, c'est u...

{Visual Basic, VB6, VB.NET, VB 2005} RENDRE UNE FENÊTRE (FORM) TRANSLUCIDE (COULEUR PARAMÉTRABLE)
Voila, comme promis, un exemple de création de fenêtre translucide. Cette création est réalisée v...

{Visual Basic, VB6, VB.NET, VB 2005} FEUILLE TRANSPARENTE
positionne une feuille transparente sur la totalité de l'écran déactive les touches génantes ctrl...

{Visual Basic, VB6, VB.NET, VB 2005} FEUILLE TRANSPARENTE
Ce code permet de render une feuille transparente , de ne voir que les controls. ...

{Visual Basic, VB6, VB.NET, VB 2005} FENETRE TRANSLUCIDE (MODIF DE LA VERSION DE MAX12)
J'ai repris le code de l'archive "FEUILLE TRANSLUCIDE (VERSION OFFICIEL)" de max12, et j'y est ajout...

{C# / C#.NET} AFFICHER LA CELLULE D'UN DATAGRIDVIEW DANS UN TEXTBOX D'UN AUTRE FORM
Bonjour, Je souhaite afficher la colonne 2 de la ligne sélectionnée dans un textBox de mon Form Com...

{Delphi} EFFET MATRIX DANS UN PANEL
Bonjour , voici un petit effet du film Matrix , il s'agit au départ d'un screensaver existant sur...

{Visual Basic, VB6, VB.NET, VB 2005} DÉGRADÉS DE COULEUR DANS LES OBJETS PAR SIMPLE CALL À UNE PROCÉDURE.
J'ai décidé de retirer toutes les sources que j'ai déposées sur ce site en raison de l'attitude de c...