vb 如何指定某颜色为透明

来源:百度知道 编辑:UC知道 时间:2024/05/10 21:33:43
悬赏30分!!

颜色 透明了 还有色么?

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Sub Form_Load()
Dim rtn As Long
Me.BackColor=0
rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取得窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体

SetLayeredWindowAttributes Me.hwnd, &H0, 0, LWA_COLO