?? 06.txt
字號:
Cool 3D 浮動按鈕的模擬作法
VERSION 5.00
Begin VB.Form frmSimu3d
Caption = "浮動按鈕模擬"
ClientHeight = 1824
ClientLeft = 3108
ClientTop = 2472
ClientWidth = 2292
LinkTopic = "Form1"
ScaleHeight = 1824
ScaleWidth = 2292
Begin VB.PictureBox picPaintBoard
Height = 660
Left = 600
ScaleHeight = 612
ScaleWidth = 612
TabIndex = 0
Top = 600
Width = 660
End
Begin VB.Image imgButton
Height = 492
Left = 840
Top = 600
Width = 612
End
End
Attribute VB_Name = "frmSimu3d"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'宣告儲存按鈕圖形的變數
Private ImageStore As StdPicture
'宣告決定按鈕邊緣寬度的變數
Private BorderWidth As Single
'宣告決定按鈕浮起程度的變數
Private PaintWidth As Integer
Private Sub Form_Load()
'載入圖形到圖形儲存變數內
Set ImageStore = LoadPicture(App.Path + "\midpic.bmp")
'imgButton 是用來做為替代按鈕顯示的一個
'ImageBox,這裏同時把按鈕圖設定給它。
imgButton.Picture = ImageStore
'picPaintBoard 是一個 PictureBox,是用來作為圖形
'畫邊框的繪圖板
'因為 picPaintBoard 只是繪圖板,不須顯示
picPaintBoard.Visible = False
'AutoRedraw = True 才能作出 Image 的效果,供
'imgButton 顯示使用
picPaintBoard.AutoRedraw = True
'AutoSize = True 可以配合圖形改變大小
picPaintBoard.AutoSize = True
'ScaleMode 設為 Pixel ,有利於繪圖定位
picPaintBoard.ScaleMode = 3
'設定 imgButton 的邊緣寬度,數字愈大,邊緣寬度愈窄,
'數字愈小,邊緣寬度愈厚。寬度愈窄,漏失 Mouse_Out 的可能
'愈大,寬度愈厚,要愈往中心才收得到 Mouse_In。所以要依按
'鈕圖大小做調整,圖愈小 BorderWidth 也要愈小,但不得小於
'2,小於 2 將不會產生 Mouse_In 的狀況
BorderWidth = 5
'浮起邊緣線的寬度,一般來說數字愈大浮起狀況愈明顯,但也要
'配合圖形大小,凸出太離譜就很醜了。
PaintWidth = 2
'設定imgButton的四個座標值
Me.ScaleMode = 3
imgRect.Top = imgButton.Top
imgRect.Left = imgButton.Left
imgRect.Right = imgRect.Left + imgButton.Width
imgRect.Bottom = imgRect.Top + imgButton.Height
Set theForm = Me
'Debug.Print imgRect.Left; imgRect.Top; imgRect.Right; imgRect.Bottom
Me.ScaleMode = 1
End Sub
'這是為按鈕圖浮凸邊框線的自訂方法,基本原理是就是用
'PictureBox 的 Line 在按鈕圖的四周畫明暗不同的線,達成立體的效果。
'1.浮凸:左邊、上邊用淺色,右邊、下邊用深色
'2.凹陷:左邊、上邊用深色,右邊、下邊用淺色
Public Sub SimuCool3D(ByVal Mode As Integer, Optional ByVal LineWidth As Integer)
'參數說明:
' Mode 決定圖的凸起或凹陷
' LineWidth 決定浮凸線寬度
'規定浮凸線寬度最小為 1
If LineWidth < 1 Then
LineWidth = 1
End If
'把繪線寬度及須繪製的邊框圖形指定給繪圖板
'picPaintBoard
picPaintBoard.DrawWidth = LineWidth
picPaintBoard.Picture = ImageStore
'依 Mode 參數來決定繪浮凸圖或凹陷圖,
'Case 1 是畫浮凸圖
'Case 2 是畫凹陷圖
'Mode 0 則啥事也不做,維持原圖形
Select Case Mode
Case 1
With picPaintBoard
picPaintBoard.Line (.ScaleLeft + LineWidth, .ScaleTop + LineWidth)- _
(.ScaleWidth - LineWidth, .ScaleTop + LineWidth), &H80000005
picPaintBoard.Line -(.ScaleWidth - LineWidth, .ScaleHeight - LineWidth), &H8000000C
picPaintBoard.Line -(.ScaleLeft + LineWidth, .ScaleHeight - LineWidth), &H8
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -