vb 中怎么实现 窗体透明 但控件不透明 求 代码 谢谢
1个回答
展开全部
先把窗体的颜色换成其它的,然后在用SetLayeredWindowAttributes函数设置窗体的背景色为透明,如果觉得窗体的标题栏没透明而不美观的话,可以把窗体的BorderStyle设为0。 代码举例(在窗体代码区中加入):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 Private
Sub
Form_Load()
Me.BackColor
=
RGB(210,
210,
210)
'背景透明
Dim
crKey
As
Long,
bAlpha
As
Byte,
dwFlags
As
Long
Call
SetWindLong
dwFlags
=
1
'1
只有
crKey
指定的颜色才透明,忽略
bAlpha
参数
crKey
=
Me.BackColor
'窗体中设为透明的颜色
SetLayeredWindowAttributes
Me.hWnd,
crKey,
bAlpha,
dwFlags
End
Sub Private
Sub
SetWindLong()
'为调用
SetLayeredWindowAttributes
做准备
Dim
ExsTyle
As
Long
Const
WS_EX_Layered
=
&H80000,
GWL_ExsTyle
=
-20
ExsTyle
=
GetWindowLong(Me.hWnd,
GWL_ExsTyle)
ExsTyle
=
ExsTyle
Or
WS_EX_Layered
SetWindowLong
Me.hWnd,
GWL_ExsTyle,
ExsTyle
End
Sub
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 Private
Sub
Form_Load()
Me.BackColor
=
RGB(210,
210,
210)
'背景透明
Dim
crKey
As
Long,
bAlpha
As
Byte,
dwFlags
As
Long
Call
SetWindLong
dwFlags
=
1
'1
只有
crKey
指定的颜色才透明,忽略
bAlpha
参数
crKey
=
Me.BackColor
'窗体中设为透明的颜色
SetLayeredWindowAttributes
Me.hWnd,
crKey,
bAlpha,
dwFlags
End
Sub Private
Sub
SetWindLong()
'为调用
SetLayeredWindowAttributes
做准备
Dim
ExsTyle
As
Long
Const
WS_EX_Layered
=
&H80000,
GWL_ExsTyle
=
-20
ExsTyle
=
GetWindowLong(Me.hWnd,
GWL_ExsTyle)
ExsTyle
=
ExsTyle
Or
WS_EX_Layered
SetWindowLong
Me.hWnd,
GWL_ExsTyle,
ExsTyle
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询