如何始FORM和label变的透明,就是可以看到窗体后的背景!

moleboy 2003-10-19 01:50:28
如何始FORM和label变的透明,就是可以看到窗体后的背景!(XP中)
...全文
43 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kmzs 2003-10-19
  • 打赏
  • 举报
回复
如果要label变的透明改变它的BACKSTYLE属性就可以了。
踏平扶桑 2003-10-19
  • 打赏
  • 举报
回复
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
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

添加一个command,click中加入

Dim rtn As Long
If f1 Then'f1是个全局的变量
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 255, LWA_ALPHA
f1 = False
Else
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 150, LWA_ALPHA
f1 = True
End If
moleboy 2003-10-19
  • 打赏
  • 举报
回复
up
moleboy 2003-10-19
  • 打赏
  • 举报
回复
up
moleboy 2003-10-19
  • 打赏
  • 举报
回复
你这里可以吧窗体透明!
但是我想要改回来让他不透明改怎么办!(不重新载入窗体的情况下!)
海牛 2003-10-19
  • 打赏
  • 举报
回复
'试一试^_^

Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex 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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Public Sub TransparenceWindow(hWnd As Long, ByVal lTransparenceColor As Long)
Dim lR As Long
On Error GoTo Err1

lR = GetWindowLong(hWnd, GWL_EXSTYLE)

lR = lR Or WS_EX_LAYERED

SetWindowLong hWnd, GWL_EXSTYLE, lR

SetLayeredWindowAttributes hWnd, lTransparenceColor, 0, LWA_COLORKEY
Exit Sub
Err1:
End Sub

Private Sub Command1_Click()
Me.Label1.BackColor = RGB(0, 255, 0)
TransparenceWindow Me.hWnd, Me.Label1.BackColor
End Sub
hansong_ll 2003-10-19
  • 打赏
  • 举报
回复
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
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

Public Function SetDarkForm(ByRef pFrm As Form) As Boolean
Dim lRtn As Long

lRtn = GetWindowLong(pFrm.hwnd, GWL_EXSTYLE)
lRtn = lRtn Or WS_EX_LAYERED
SetWindowLong pFrm.hwnd, GWL_EXSTYLE, lRtn
SetLayeredWindowAttributes pFrm.hwnd, 0, 200, LWA_ALPHA
End Function
LCAAA 2003-10-19
  • 打赏
  • 举报
回复
如果要label变的透明改变它的BACKSTYLE属性就可以了。

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧