如何改变vb中picturebox的透明度?

我想知道是不用程序,直接在属性框里调,能实现吗... 我想知道是不用程序,直接在属性框里调,能实现吗 展开
 我来答
xiayu50000
2009-03-06 · 超过55用户采纳过TA的回答
知道答主
回答量:184
采纳率:100%
帮助的人:0
展开全部
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, _
ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) As Long

Public Const GetWinLStyle = (-20)
Public Const WinAlpha = &H2
Public Const ColorSet = &H1
Public Const SetWinLLay = &H80000
Sub SetNewWindow(frm As picturebox, ByVal sColor As Long, ByVal sAlpha As Long) '//最好不用
Dim NewStyle As Long
If sColor = 0 Then
sColor = vbRed
Else
sColor = sColor
End If
If sAlpha = 0 Then
sAlpha = 0
Else
sAlpha = sAlpha
End If

NewStyle = GetWindowLong(frm.hWnd, GetWinLStyle)
NewStyle = NewStyle Or SetWinLLay
SetWindowLong frm.hWnd, GetWinLStyle, NewStyle
SetLayeredWindowAttributes frm.hWnd, sColor, sAlpha, ColorSet
End Sub
上面的sColor 设置透明的PCBOX颜色,sAlpha 透明度
或者可以用API
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
实现

可以在网上查查看

picturebox 的属性上修改
好象目前还没有看见有高手直接用属性修改的
一般都采用函数的方式去完成的
VB中设置图片和ASP这些网页程序不同
应该没有直接设置的方法,具体的上面我已经给你部分的代码,应该可以实现这种效果
我再给你一份代码

API声明放在模块里
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, _
ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) As Long

Public Const GetWinLStyle = (-20)
Public Const WinAlpha = &H2
Public Const ColorSet = &H1
Public Const SetWinLLay = &H80000

以下代码放在FORM_LOAD中
PICTUREBOX 名称为PCB
Dim NowStyle As Long
NowStyle = GetWindowLong(PCB.hWnd, GetWinLStyle) '取得当前窗口属性
Call SetWindowLong(PCB.hWnd, GetWinLStyle, NowStyle Or SetWinLLay)
'加上一个透明属性
Call SetLayeredWindowAttributes(PCB.hWnd, 0, 200, WinAlpha)
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式