如果你看膩了VB的中規中矩的按鈕,有時想改變一下的話,本文或許對你有所啟發。以下二例用Line方法結合其它手段,在窗體上繪制出別具一格的“按鈕”,呵呵,還是有那么一點兒新意的(怎么象是吹牛?)。建議在不需要太多的按鈕的窗體中使用。
例一:用Line方法制作初始時為平面、鼠標移到時突出的按鈕,此類按鈕其實更象是第一層菜單,可為之通過Form_MouseDown或者Form_MouseUp編寫類似于Click的事件。當然了,用標簽+線條或者+ImageBox來實現更簡單些。
Private Sub Form_Load()
Me.AutoRedraw = True CurrentX = 280: CurrentY = 150 Me.Print "Exit" Me.Caption = "請將鼠標移近文字觀察效果" End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then End End If End If End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then Me.Caption = "左鍵單擊按鈕退出程序" Line (100, 100)-(100, 400), vbWhite Line (100, 100)-(800, 100), vbWhite Line (100, 400)-(800, 400), vbBlack Line (800, 100)-(800, 425), vbBlack '多出25是為了讓右下角更封閉 Me.ForeColor = vbBlue CurrentX = 280: CurrentY = 150 Me.Print "Exit" Else Me.Cls CurrentX = 280: CurrentY = 150 Me.ForeColor = vbBlack Me.Print "Exit" Me.Caption = "請將鼠標移近文字觀察效果" End If
End Sub
例二:用Line方法結合PictureBox(作按鈕容器用)制作有立體感的按鈕,很Cool喲。要試用本例,請在窗體上缺省繪制一個1000*700的PictureBox控件。
Private Sub Form_Load()
Dim k As Integer Picture1.AutoRedraw = True Me.AutoRedraw = True
'繪制出灰度的效果 For k = 0 To 20 Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k) Next k
Picture1.CurrentX = 250: Picture1.CurrentY = 250 Picture1.Print "Hello"
End Sub
'繪制矩形 Sub Rect(obj As Object, X As Integer, Y As Integer, iW As Integer, iH As Integer, iC As Long) obj.Line (X, Y)-(X + iW, Y), iC obj.Line -Step(0, iH), iC obj.Line -Step(-iW, 0), iC obj.Line -Step(0, -iH), iC End Sub
'鼠標在窗體移動時按鈕保持灰度的原貌 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) For k = 0 To 20 Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k) Picture1.ForeColor = vbBlack Picture1.CurrentX = 250: Picture1.CurrentY = 250 Picture1.FontBold = False Picture1.Print "Hello" Next k End Sub
'鼠標移動到圖片框時按鈕形狀發生變化:底色為深色,按鈕周邊帶色彩邊框,文字變色 Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim k As Integer For k = 0 To 20 Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(8 * k, 12 * k, 8 * k) Picture1.ForeColor = vbRed Picture1.CurrentX = 250: Picture1.CurrentY = 250 Picture1.Print "Hello" Next End Sub
|