【VB】窗体透明二:窗体逐渐变透明(包括控件)

前端之家收集整理的这篇文章主要介绍了【VB】窗体透明二:窗体逐渐变透明(包括控件)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


'添加一个shape

'添加一个PicturebBox,依它为容器添加一个shape,背景色设为蓝色

'添加一个时钟控件

  1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long,ByVal nIndex As Long) As Long
  2. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long) As Long
  3. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long,ByVal crKey As Long,ByVal bAlpha As Byte,ByVal dwFlags As Long) As Long
  4. Const WS_EX_LAYERED = &H80000
  5. Const GWL_EXSTYLE = (-20)
  6. Const LWA_ALPHA = &H2
  7. Const LWA_COLORKEY = &H1
  8. Dim tmd As Long
  9. Private Sub Form_Load()
  10. Show
  11. Shape1.BackColor = &H80000002
  12. Shape1.BackStyle = 1
  13. tmd = 255
  14. Timer1.Interval = 50
  15. Shape1.Width = Picture1.Width
  16. SetWindowLong hwnd,GWL_EXSTYLE,WS_EX_LAYERED
  17. SetLayeredWindowAttributes hwnd,tmd,LWA_ALPHA '越少越透明,限制0-255
  18. End Sub
  19.  
  20. Private Sub Timer1_Timer()
  21. On Error Resume Next
  22. tmd = tmd - 1
  23. SetLayeredWindowAttributes hwnd,LWA_ALPHA
  24. Shape1.Width = Shape1.Width - Picture1.Width / 255
  25. If tmd < 0 Then
  26. Timer1.Enabled = False
  27. MsgBox "OK!"
  28. End If
  29. End Sub

猜你在找的VB相关文章