如果你看腻了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->