外婆家总店地址电话:用VB让控件和窗体一起淡入淡出效果

来源:百度文库 编辑:高考问答 时间:2024/05/01 04:54:21
Private Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Long
这个只有窗体有效果其他控件都被覆盖了看不到标签的文字显示不出来啊
Private Sub TraningForm(s As Integer)
Dim LRtn As Long
LRtn = GetWindowLong(hwnd, GWL_EXSTYLE)
LRtn = LRtn Or &H80000
SetWindowLong hwnd, (-20), LRtn
SetLayeredWindowAttributes hwnd, 0, s, &H2
End Sub

Private Sub Form_Load()
Timer1.Interval = 1
Call TraningForm(Int(1))
End Sub

Private Sub Form_Unload(Cancel As Integer)
For i = 255 To 0 Step -1
Call TraningForm(Int(i))
Next i
End Sub

Private Sub Image1_Click()
Unload Form1
End Sub

Private Sub Timer1_Timer()
If i < 240 Then
i = i + 10
Call TraningForm(Int(i))
Else
Form1.Show
Timer1.Enabled = False
End If
End Sub

声明 api

Private Declare Function SetLayeredWindowAttributes Lib \"user32\" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

使用 api:

SetLayeredWindowAttributes Me.hWnd, 0, 127, LWA_ALPHA

那个127换成透明度(0-255),你用循环或者timer从1到255旧可以实现了

不过 楼上说的那样做的话,会发现在淡入的时候整个窗口其实是黑色的