SetLayeredWindowAttributesce 能不能让控件透明窗体不透明 VB

首先给15分,后追加35分,我快没分了,高手见谅。告诉你这样做的目的吧,想让富文本框有背景图案,如果不用这个办法,也能达到效果(前提是不影响编辑),一样加分!这边还有一个... 首先给15分,后追加35分,我快没分了,高手见谅。
告诉你这样做的目的吧,想让富文本框有背景图案,如果不用这个办法,也能达到效果(前提是不影响编辑),一样加分!
这边还有一个差不多的问题,如果你能解决,那边的分也给你
http://zhidao.baidu.com/question/176657770.html

非常感谢wannalcxl的回答,但是你的代码那一下就完全透明了,能不能调节透明度啊,不然也不美观
展开
 我来答
734172930
2010-08-27 · 超过19用户采纳过TA的回答
知道答主
回答量:52
采纳率:0%
帮助的人:45.7万
展开全部
这样吧
在窗体上画一个HScroll(横向滚动条),Max = 250,Min = 1, value = 200
再画一个Timer(计时器),Interval = 500
HScroll是用来调整透明度的,250是不透明。
代码这样就行了:

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = -20
Private Const LWA_ALPHA As Long = &H2
Private Const WS_EX_LAYERED As Long = &H8000
Private Declare Function SetLayeredWindowAttributes Lib "user32 " (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwflags As Long) As Long

Private Sub Timer1_Timer()
Dim FAttri As Long
FAttri = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, FAttri Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hwnd, 0, HScroll1.Value, LWA_ALPHA)
End Sub

不行的话写邮箱,发给你
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
风华正茂人
2010-09-08 · TA获得超过4602个赞
知道小有建树答主
回答量:1171
采纳率:0%
帮助的人:2199万
展开全部
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()
Form1.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
'Label1.BackColor = HFF0000 '这里就可以显示出来
Dim stn As Long
BorderStyler = 0
stn = GetWindowLong(hwnd, GWL_EXSTYLE)
stn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, HFF0000, 0, LWA_COLORKEY
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
mislandeer
2010-08-26 · TA获得超过307个赞
知道小有建树答主
回答量:397
采纳率:0%
帮助的人:437万
展开全部
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(RichTextBox1.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong RichTextBox1.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes RichTextBox1.hwnd, 0, 200, LWA_ALPHA
End Sub'200是透明度
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wannalcxl
2010-08-26 · TA获得超过260个赞
知道小有建树答主
回答量:640
采纳率:0%
帮助的人:628万
展开全部
看下是不是这个效果?
Option Explicit
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Const GWL_EXSTYLE = (-20)
Const WS_EX_TRANSPARENT = &H20&

Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(RichTextBox1.hwnd, GWL_EXSTYLE)
SetWindowLong RichTextBox1.hwnd, GWL_EXSTYLE, rtn Or WS_EX_TRANSPARENT
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式