vb中如何使窗体半透明,控件不透明?

如题PrivateDeclareFunctionGetWindowLongLib"user32"Alias"GetWindowLongA"(ByValhwndAsLong... 如题
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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA '100值可调,0-255之间,越小透明度越高
' SetLayeredWindowAttributes hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY '将窗体上的黑颜色去掉
End Sub

使用LWA_ALPHA,窗体和控件都半透明。使用LWA_COLORKEY,可将指定颜色透明,但不是半透明。有什么方法可将窗体半透明控件不透明吗?
展开
 我来答
ljl88900
推荐于2016-02-08 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2651万
展开全部
下面代码能能使窗体透明,但控件不透明:

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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Sub Form_Load()
Dim rtn As Long, ctrol As Control
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_TRANSPARENT
SetWindowLong hwnd, GWL_EXSTYLE, rtn
Me.Show
DoEvents
For Each ctrol In Me.Controls
ctrol.Refresh
Next
'SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA '100值可调,0-255之间,越小透明度越高
'SetLayeredWindowAttributes hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY '将窗体上的黑颜色去掉
End Sub
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
bater2000
2010-05-10 · TA获得超过1486个赞
知道小有建树答主
回答量:803
采纳率:0%
帮助的人:1081万
展开全部
VB6里要想让窗体透明可难啦,而且效果不好。

如果控件有自己的hwnd窗体句柄,只要把hwnd窗体句柄设置成指定的控件或者窗体的hwnd,也就是说精确的设定需要半透明的窗体句柄。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zgwxm
2010-05-11 · 经典歌曲、名人名家歌曲视频
zgwxm
采纳数:1792 获赞数:21142

向TA提问 私信TA
展开全部
半透明窗体

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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA
End Sub

完全透明窗体

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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Me.BackColor = &HFF0000
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, &HFF0000, 0, LWA_COLORKEY
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
宁秀梅寸巳
2019-12-22 · TA获得超过3.6万个赞
知道小有建树答主
回答量:1.2万
采纳率:30%
帮助的人:1032万
展开全部
const
lwa_colorkey
=
&h1
const
lwa_alpha
=
&h2
const
gwl_exstyle
=
(-20)
const
ws_ex_layered
=
&h80000
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()
dim
ret
as
long
'set
the
window
style
to
'layered'
ret
=
getwindowlong(me.hwnd,
gwl_exstyle)
ret
=
ret
or
ws_ex_layered
setwindowlong
me.hwnd,
gwl_exstyle,
ret
'set
the
opacity
of
the
layered
window
to
128
'我们可以设置这个数值来控制透明程度
setlayeredwindowattributes
me.hwnd,
0,
128,
lwa_alpha
end
sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
a421809265
2019-01-12
知道答主
回答量:54
采纳率:0%
帮助的人:9.6万
展开全部
在最新的visual Studio编译环境下,安装的VBasic的窗口form控件在属性中是可以直接设置控件的不透明度百分比,而且所有参数都有中文说明,在属性栏中对应的英文参数是Opacity,
太老的vb6.0感觉界面还是windows 2000样子一样,新的visual studio 界面很友好啦,集成了vb到VC++一整套的,我也是入门,看起来VS明显界面更友好,而且也有教程可以学习,
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式