最好加点效果,我参考网上的代码写的慢慢出现和消失 Option Explicit Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long '其中hwnd是透明窗体的句柄,crKey为颜色值,bAlpha是透明度, '取值范围是[0,255],dwFlags是透明方式,可以取两个值: '当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效; '当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色 '为crKey的地方将变为透明 --这个功能很有用: '我们不必再为建立不规则形状的窗体而调用一大堆区域分析、创建、合并函数了, '只需指定透明处的颜色值即可,哈哈哈哈!请看具体代码。Public Const WS_EX_LAYERED = &H80000 Public Const GWL_EXSTYLE = (-20) Public Const LWA_ALPHA = &H2 Public Const LWA_COLORKEY = &H1'Clarity:透明 ——此过程让窗体透明,不可见。需在Form_Load中调用。 Public Sub formClarity(frmClarity As Form) Dim rtn As Long Dim i As Integer rtn = GetWindowLong(frmClarity.hwnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong frmClarity.hwnd, GWL_EXSTYLE, rtn SetLayeredWindowAttributes frmClarity.hwnd, &H80000012, 0, LWA_ALPHA End Sub'fadein :渐显 ——此过程让窗体逐渐显现出来。需在Form_Resize中调用。 Public Sub formFadein(frmFadein As Form) Dim rtn As Long Dim i As Integer rtn = GetWindowLong(frmFadein.hwnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong frmFadein.hwnd, GWL_EXSTYLE, rtn For i = 0 To 200 Step 20 SetLayeredWindowAttributes frmFadein.hwnd, &H80000012, i, LWA_ALPHA frmFadein.Refresh Next End Sub'scumble :渐淡画法 ——此过程让窗体逐渐淡化,需在Form_Unload中调用 Public Sub formScumble(frmScumble As Form) Dim rtn As Long Dim i As Integer rtn = GetWindowLong(frmScumble.hwnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong frmScumble.hwnd, GWL_EXSTYLE, rtn For i = 255 To 0 Step -20 SetLayeredWindowAttributes frmScumble.hwnd, &H80000012, i, LWA_ALPHA frmScumble.Refresh Next End Sub
Private Sub Form_Load() Timer1.Interval = 1000 End SubPrivate Sub Timer1_Timer() Static i As Integer i = i + 1 If i = 5 Then Form2.Show Unload Me Set Form1 = Nothing End If End Sub
Option Explicit
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'其中hwnd是透明窗体的句柄,crKey为颜色值,bAlpha是透明度,
'取值范围是[0,255],dwFlags是透明方式,可以取两个值:
'当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效;
'当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色
'为crKey的地方将变为透明 --这个功能很有用:
'我们不必再为建立不规则形状的窗体而调用一大堆区域分析、创建、合并函数了,
'只需指定透明处的颜色值即可,哈哈哈哈!请看具体代码。Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2
Public Const LWA_COLORKEY = &H1'Clarity:透明 ——此过程让窗体透明,不可见。需在Form_Load中调用。
Public Sub formClarity(frmClarity As Form)
Dim rtn As Long
Dim i As Integer
rtn = GetWindowLong(frmClarity.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong frmClarity.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes frmClarity.hwnd, &H80000012, 0, LWA_ALPHA
End Sub'fadein :渐显 ——此过程让窗体逐渐显现出来。需在Form_Resize中调用。
Public Sub formFadein(frmFadein As Form)
Dim rtn As Long
Dim i As Integer
rtn = GetWindowLong(frmFadein.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong frmFadein.hwnd, GWL_EXSTYLE, rtn
For i = 0 To 200 Step 20
SetLayeredWindowAttributes frmFadein.hwnd, &H80000012, i, LWA_ALPHA
frmFadein.Refresh
Next
End Sub'scumble :渐淡画法 ——此过程让窗体逐渐淡化,需在Form_Unload中调用
Public Sub formScumble(frmScumble As Form)
Dim rtn As Long
Dim i As Integer
rtn = GetWindowLong(frmScumble.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong frmScumble.hwnd, GWL_EXSTYLE, rtn
For i = 255 To 0 Step -20
SetLayeredWindowAttributes frmScumble.hwnd, &H80000012, i, LWA_ALPHA
frmScumble.Refresh
Next
End Sub
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i = 5 Then
Form2.Show
Unload Me
Set Form1 = Nothing
End If
End Sub