netice 2006-10-13 21:33
PictureBox 控件能把背景为透明的吗?
关于控件叠加的时候。。为什么不能把lab控件放在shockwaveFLASH控件上面?
。。。但是PictureBox 控件可以放在其上面。。但是好象不能把它的背景设置为透明的哦。。。。
有没有简单点的办法实现呢?。。。。
Nothing 2006-10-13 22:44
PictureBox不能把背景设置成透明。
不过可以用API函数将PictureBox做成你要的型形状
SetAutoRgna Picture1
下面是函数,API声明我就省了
[code]
Public Sub SetAutoRgna(hForm As PictureBox, Optional transColor As Byte = vbNull)
Dim X As Long, Y As Long
Dim Rgn1 As Long, Rgn2 As Long
Dim SPos As Long, EPos As Long
Dim bm As BITMAP
Dim hbm As Long
Dim wID As Long, Hgt As Long
Dim xoff As Long, yoff As Long
Dim bmbyte() As Byte
'获取窗体背景图片尺寸
hbm = hForm.Picture
GetObject hbm, Len(bm), bm
wID = bm.bmWidth
Hgt = bm.bmHeight
ReDim bmbyte(1 To wID, 1 To Hgt)
GetBitmapBits hbm, wID * Hgt, bmbyte(1, 1) '获取图像数组
'如果没有传入transColor参数,则用第一个像素作为透明色
If transColor = vbNull Then transColor = bmbyte(1, 1)
Rgn1 = CreateRectRgn(0, 0, 0, 0)
For Y = 1 To Hgt '逐行扫描
X = 0
Do
X = X + 1
While (bmbyte(X, Y) = transColor) And (X < wID)
X = X + 1 '跳过是透明色的点
Wend
SPos = X
While (bmbyte(X, Y) <> transColor) And (X < wID)
X = X + 1 '跳过不是透明色的点
Wend
EPos = X - 1
'这一段是合并区域
If SPos <= EPos Then
Rgn2 = CreateRectRgn(SPos - 1 + xoff, Y - 1 + yoff, EPos + xoff, Y + yoff)
CombineRgn Rgn1, Rgn1, Rgn2, RGN_OR
DeleteObject Rgn2
End If
Loop Until X >= wID
Next Y
SetWindowRgn hForm.hwnd, Rgn1, True '设定窗体形状区域
DeleteObject Rgn1
End Sub
[/code]
netice 2006-10-13 23:31
谢谢,不过对于我来说有点复杂。。。
。。毕竟偶没学过API函数,看到他们就头疼。。。。还是想想用其他办法了