制作VB另類按鈕
發(fā)表時(shí)間:2024-02-24 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]如果你看膩了VB的中規(guī)中矩的按鈕,有時(shí)想改變一下的話,本文或許對(duì)你有所啟發(fā)。以下二例用Line方法結(jié)合其它手段,在窗體上繪制出別具一格的“按鈕”,呵呵,還是有那么一點(diǎn)兒新意的(怎么象是吹牛?)。建議在不需要太多的按鈕的窗體中使用。 例一:用Line方法制作初始時(shí)為平面、鼠標(biāo)移到時(shí)突出的按鈕,此類按...
如果你看膩了VB的中規(guī)中矩的按鈕,有時(shí)想改變一下的話,本文或許對(duì)你有所啟發(fā)。以下二例用Line方法結(jié)合其它手段,在窗體上繪制出別具一格的“按鈕”,呵呵,還是有那么一點(diǎn)兒新意的(怎么象是吹牛?)。建議在不需要太多的按鈕的窗體中使用。
例一:用Line方法制作初始時(shí)為平面、鼠標(biāo)移到時(shí)突出的按鈕,此類按鈕其實(shí)更象是第一層菜單,可為之通過Form_MouseDown或者Form_MouseUp編寫類似于Click的事件。當(dāng)然了,用標(biāo)簽+線條或者+ImageBox來實(shí)現(xiàn)更簡(jiǎn)單些。
Private Sub Form_Load()
Me.AutoRedraw = True
CurrentX = 280: CurrentY = 150
Me.Print "Exit"
Me.Caption = "請(qǐng)將鼠標(biāo)移近文字觀察效果"
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 = "請(qǐng)將鼠標(biāo)移近文字觀察效果"
End If
End Sub
例二:用Line方法結(jié)合PictureBox(作按鈕容器用)制作有立體感的按鈕,很Cool喲。要試用本例,請(qǐng)?jiān)诖绑w上缺省繪制一個(gè)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
'鼠標(biāo)在窗體移動(dòng)時(shí)按鈕保持灰度的原貌
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
'鼠標(biāo)移動(dòng)到圖片框時(shí)按鈕形狀發(fā)生變化:底色為深色,按鈕周邊帶色彩邊框,文字變色
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