自定义形状窗体
在用vb编程中,有时,我们需要使用一个跟不规则背景有相同形状的不规则窗体,怎么办呢?
首先,我们需要设置无边框窗体,
即:borderstyle=0
其次,把背景图片覆盖不住的窗体背景设置成透明。
这需要用到API函数,
Private DeclareFunction GetWindowLong Lib "user32" Alias "GetWindowLongA"(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private DeclareFunction SetWindowLong Lib "user32" Alias "SetWindowLongA"(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private DeclareFunction SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long,ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private ConstWS_EX_LAYERED = &H80000
Private ConstGWL_EXSTYLE = (-20)
Private ConstLWA_ALPHA = &H2
Private ConstLWA_COLORKEY = &H1
'屏蔽窗体指定颜色,这里是屏蔽的蓝色,前提要把窗体背景颜色设置成蓝色
Private SubForm_Load()
Dim rtn As Long
rtn =GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn OrWS_EX_LAYERED
SetWindowLong hwnd,GWL_EXSTYLE, rtn
SetLayeredWindowAttributeshwnd, vbBlue, 0, LWA_COLORKEY
end sub
这样就得到了你想要的自定义窗体了。