使用那個標題的最大化.最小化.還有關閉按鈕消失.然后用自己所擁有的PS圖片添加.需要3張. 還有界面透明和界面圓角. 詳細如下.
標題欄的轉換:
首先把Form的BorderStyle屬性設置為0-None,上面的標題欄就沒了(最大化,最小話和關閉按鈕弄沒了就只能這樣),然後在窗體上添加3個PictureBox控件(建議不要用image控件,因為PictureBox可以控制凹凸感),圖片你就自己弄了,先把3個picturebox控件的borderstyle設為0,下面是3個按鈕的代碼:
'mouse_down和mouse_up主要是讓控件點擊有凹凸感
Option Explicit
Dim hasMax As Boolean '窗體最大化標志
Private Sub Form_Load()
hasMax = False
End Sub
Private Sub Picture1_Click()
'最小化
Form1.WindowState = 1
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BorderStyle = 1
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BorderStyle = 0
End Sub
Private Sub Picture2_Click()
'最大化
If hasMax Then
Form1.WindowState = 0 '如果已經最大化則還原窗體大小
Else
Form1.WindowState = 2
End If
hasMax = Not hasMax
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture2.BorderStyle = 1
End Sub
Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture2.BorderStyle = 0
End Sub
Private Sub Picture3_Click()
'關閉
End
End Sub
Private Sub Picture3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture3.BorderStyle = 1
End Sub
Private Sub Picture3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture3.BorderStyle = 0
End Sub
接下來是透明度.
Option Explicit
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Dim sty As Long
sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
sty = sty Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
SetLayeredWindowAttributes Me.hwnd, 0, 190, LWA_ALPHA '190是透明度,修改
End Sub
接下來是界面圓角.
'將窗體的BorderStyle屬性設為0
'然後聲明API函數,如下:
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
'我們先來了解一下這幾個函數
'函數CreateRoundRectRgn用於創建一個圓角矩形,該矩形由X1,Y1-X2,Y2確定,
'並由X3,Y3確定的橢圓描述圓角弧度
'CreateRoundRectRgn參數 類型及說明
'X1,Y1 Long,矩形左上角的X,Y坐標
'X2,Y2 Long,矩形右下角的X,Y坐標
'X3 Long,圓角橢圓的寬。其范圍從0(沒有圓角)到矩形寬(全圓)
'Y3 Long,圓角橢圓的高。其范圍從0(沒有圓角)到矩形高(全圓)
'SetWindowRgn用於將CreateRoundRectRgn創建的圓角區域賦給窗體
'DeleteObject用於將CreateRoundRectRgn創建的區域刪除,這是必要的,否則不必要的佔用電腦內存
'接下來聲明一個全局變量,用來獲得區域句柄,如下:
Dim outrgn As Long
Option Explicit
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
'然後分別在窗體Activate()事件和Unload事件中輸入以下代碼
Private Sub Form_Activate()
Call rgnform(Me, 25, 25) '調用子過程
End Sub
Private Sub Form_Load()
Dim sty As Long
sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
sty = sty Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
SetLayeredWindowAttributes Me.hwnd, 0, 180, LWA_ALPHA '190是透明度,修改
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteObject outrgn '將圓角區域使用的所有系統資源釋放
End Sub
'接下來我們開始編寫子過程
Private Sub rgnform(ByVal frmbox As Form, ByVal fw As Long, ByVal fh As Long)
Dim w As Long, h As Long
w = frmbox.ScaleX(frmbox.Width, vbTwips, vbPixels)
h = frmbox.ScaleY(frmbox.Height, vbTwips, vbPixels)
outrgn = CreateRoundRectRgn(0, 0, w, h, fw, fh)
Call SetWindowRgn(frmbox.hwnd, outrgn, True)
End Sub
'好了,程序可以直接運行了,看看效果如何,如果把Call rgnform(Me, 20, 20)中
'的20改為50又會怎樣呢?
'60呢?100呢?
'所以通過改變參數fw和fh的值就可以實現圓角窗體了。 |