vb 窗体透明效果控件不透明

'窗体透明,控件不透明的代码:
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 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 Sub Form_Load()
   Me.BackColor = &HFF0000
   Dim rtn As Long
   Dim BorderStyler
   BorderStyler = 0
   rtn = getwindowlong(hwnd,GWL_EXSTYLE)
   rtn = rtn Or WS_EX_layered
   SetwindowLong hwnd,GWL_EXSTYLE,rtn
   SetlayeredWindowAttributes hwnd,&HFF0000,LWA_COLORKEY
End Sub
 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

‘窗体逐渐变透明:
'添加一个PicturebBox,依它为容器添加一个shape,背景色设为蓝色
'添加一个时钟控件
Private Declare Function getwindowlong Lib "user32" Alias "getwindowlongA" (ByVal hwnd As Long,ByVal dwFlags As Long) As Long
Const WS_EX_layered = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Dim tmd As Long
Private Sub Form_Load()
Show
Shape1.BackColor = &H80000002
Shape1.BackStyle = 1
tmd = 255
Timer1.Interval = 50
Shape1.Width = Picture1.Width
     SetwindowLong hwnd,WS_EX_layered
     SetlayeredWindowAttributes hwnd,tmd,LWA_ALPHA '越少越透明,限制0-255
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
tmd = tmd - 1
SetlayeredWindowAttributes hwnd,LWA_ALPHA
Shape1.Width = Shape1.Width - Picture1.Width / 255
If tmd < 0 Then
  Timer1.Enabled = False
  MsgBox "OK!"
End If
End Sub

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...