VB实现窗体淡入淡出

添加模块,代码如下

Option Explicit
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_LAYERED = &H80000

Public Sub setfrm(frm As Form, ByVal limpid As Long) ' 设置窗体透明度
    Call SetWindowLong(frm.hWnd, GWL_EXSTYLE, GetWindowLong(frm.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
    Call SetLayeredWindowAttributes(frm.hWnd, 0, limpid, LWA_ALPHA)    'limpid在0--255之间
End Sub

========

窗体级变量

Option Explicit
Dim showfrm As Boolean
Dim i As Integer
Dim closefrm As Boolean

 

窗体登陆事件


Private Sub Form_Load()
Call setfrm(Me, 0)
showfrm = True
End Sub

窗体卸载事件

Private Sub Form_Unload(Cancel As Integer)
If closefrm = True Then Exit Sub
Cancel = 1
showfrm = False
Timer1.Enabled = True
End Sub

timer事件

Private Sub Timer1_Timer()
If showfrm Then
   i = i + 3
   If i >= 255 Then
        i = 255
        Timer1.Enabled = False
    End If
Else
   i = i - 2
   If i <= 0 Then
        i = 0
        closefrm = True
        Call talkewithme
        Unload Me
        Exit Sub
        Timer1.Enabled = False
    End If
End If
setfrm Me, i
End Sub

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值