Grâce à ce code, on peut modifier la transparence d'une feuile de 0 à 100%. Ne marche que sous Windows 2000, XP, ... et suivants.
ET CA MARCHE !
Valeur de alpha = 255 >> tout visible
Valeur de alpha = 0 >> invisible
A mettre dans un module.
Source / Exemple :
Option Explicit
Global Const WS_EX_LAYERED = &H80000
Global Const LWA_COLORKEY = &H1
Global Const LWA_ALPHA = &H2
Global Const GWL_EXSTYLE = (-20)
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Sub ActiveTransparence(Fenêtre As Form, Optional ByVal AlphaInit As Byte = 255)
SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
ChangeTransparence Fenêtre, AlphaInit
End Sub
Sub ChangeTransparence(Fenêtre As Form, ByVal Alpha As Byte)
SetLayeredWindowAttributes Fenêtre.hWnd, 0, Alpha, LWA_ALPHA
End Sub
Sub DésactiveTransparence(Fenêtre As Form)
SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) - WS_EX_LAYERED
End Sub
Conclusion :
Un conseil : ne laissez pas activé la transparence si elle ne sert pas, car cela utilise plus de mémoire !
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.