自定义形状窗体
在用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
這樣就得到了你想要的自定義窗體了。
總結
- 上一篇: 现货是什么意思
- 下一篇: 企业上市流程步骤,有以下六步