如果你看膩了VB的中規中矩的按鈕,有時想改變一下的話,本文或許對你有所啟發。以下二例用Line方法結合其它手段,在窗體上繪制出別具一格的“按鈕”,呵呵,還是有那麼一點兒新意的(怎麼象是吹牛?)。建議在不需要太多的按鈕的窗體中使用。
例一:用Line方法制作初始時為平面、鼠標移到時突出的按鈕,此類按鈕其實更象是第一層菜單,可為之通過Form_MouseDown或者Form_MouseUp編寫類似於Click的事件。當然了,用標簽 線條或者 ImageBox來實現更簡單些。
PrivateSubForm_Load()
Me.AutoRedraw=True
CurrentX=280:CurrentY=150
Me.Print"Exit"
Me.Caption="請將鼠標移近文字觀察效果"
EndSub
PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
IfX<=900AndX>=100AndY<=500AndY>=100Then
End
EndIf
EndIf
EndSub
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfX<=900AndX>=100AndY<=500AndY>=100Then
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="請將鼠標移近文字觀察效果"
EndIf
EndSub
例二:用Line方法結合PictureBox(作按鈕容器用)制作有立體感的按鈕,很Cool喲。要試用本例,請在窗體上缺省繪制一個1000*700的PictureBox控件。
PrivateSubForm_Load()
DimkAsInteger
Picture1.AutoRedraw=True
Me.AutoRedraw=True
'繪制出灰度的效果
Fork=0To20
RectPicture1,5*k,5*k,Picture1.ScaleWidth-10*k,Picture1.ScaleHeight-10*k,RGB(255-5*k,255-5*k,255-5*k)
Nextk
Picture1.CurrentX=250:Picture1.CurrentY=250
Picture1.Print"Hello"
EndSub
'繪制矩形
SubRect(objAsObject,XAsInteger,YAsInteger,iWAsInteger,iHAsInteger,iCAsLong)
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
EndSub
'鼠標在窗體移動時按鈕保持灰度的原貌
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
Fork=0To20
RectPicture1,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"
Nextk
EndSub
'鼠標移動到圖片框時按鈕形狀發生變化:底色為深色,按鈕周邊帶色彩邊框,文字變色
PrivateSubPicture1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
DimkAsInteger
Fork=0To20
RectPicture1,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
EndSub->