怎样把VB里面的PictureBox控件的背景设置成透明?
如题,我知道要用到API函数,具体怎样设置我不清楚,函数如下:实现窗口透明:PrivateDeclareFunctionGetWindowLongLib"user32"A...
如题,我知道要用到API函数,具体怎样设置我不清楚,函数如下:实现窗口透明:Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Const WS_EX_LAYERED = &H80000Private Const GWL_EXSTYLE = (-20)Private Const LWA_ALPHA = &H2Private Const LWA_COLORKEY = &H1Private Sub Form_Load()Dim sty As Longsty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)Form1.Print stysty = sty Or WS_EX_LAYERED Or WS_EX_TRANSPARENTForm1.Print stySetWindowLong Me.hwnd, GWL_EXSTYLE, stySetLayeredWindowAttributes Me.hwnd, 0, 192, LWA_ALPHAEnd Sub请高收赐教!!!
展开
3个回答
推荐于2016-01-15
展开全部
如果是直接在窗体上显示的背景图(即设置form1.BackgroundImage属性来显示),那只须设置Label1.BackColor=Color.Transparent即可;
如果是使用一个PictureBox来显示背景图,则需要在运行时将Label控件动态加载到PictureBox中去,使PictureBox成为Label的容器(这一点在设计时做不到,因为PictureBox不是一容器控件),再将Label的BackColor设置为Color.Transparent即可:
dim lbl as new Label
lbl.backcolor=color.Transparent
lbl.text="China"
PictureBox1.Controls.Add (lbl)
这样一来就OK了。
如果是使用一个PictureBox来显示背景图,则需要在运行时将Label控件动态加载到PictureBox中去,使PictureBox成为Label的容器(这一点在设计时做不到,因为PictureBox不是一容器控件),再将Label的BackColor设置为Color.Transparent即可:
dim lbl as new Label
lbl.backcolor=color.Transparent
lbl.text="China"
PictureBox1.Controls.Add (lbl)
这样一来就OK了。
2013-05-11
展开全部
'添加模块一个模块声明如下APIPublic Declare Function GdiTransparentBlt Lib "gdi32" (ByVal hdc1 As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal W1 As Long, ByVal H1 As Long, ByVal Hdc2 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal W2 As Long, ByVal H2 As Long, ByVal Color As Long) As Long'hdc1 要绘图目标句柄'x1图片显示的横坐标位置'y1图片显示的纵坐标位置'w1图片缩放比例宽度'h1图片缩放比例高度'hdc2要绘制透明色的图片或控件(这里指picture)'x2一般这里填0(图片左上角起始坐标)'y2一般这里填0(图片左上角起始坐标)'w2图片宽度'h2图片高度'color绘制颜色(RGB(255,255,255)为透明色)'picture控件属性设置成visible=falseautosize=trueautoredraw=trueborderstyle=0窗体autoredraw=true简单例子Private Sub Form_Load()GdiTransparentBlt form1.hDC, 0, 0, form1.picture1.Width, form1.picture1.Height, form1.picture1.hDC, 0, 0, form1.picture1.Width, form1.picture1.Height, RGB(255, 255, 255) '画图End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-05-11
展开全部
没学过VB,但是你们VB不是有那个选项的吗?可以选择透明的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询