|
最近给工厂写了个在内部传递消息的小工具,为了美化界面写了一个用PictureBox+API做图形按钮的图形按钮类。
包含6个属性和4个事件:
属性 picBox 关联的PictureBox控件(Form和关联的PictureBox的属性ScaleMode=3,且关联的PictureBox应设为非3D显示,自动重绘为True,没有边框)
picDown,picOver,picUp,picXX 分别为按钮按下,鼠标经过,不可用,按钮弹起(正常状态)时显示的图片。设置这些属性的时候需要用Set
vEnabled boolean型,表示按钮是否可用
事件 vMouseDown,vMouseOut,vMouseOver,vMouseUp 分别为鼠标按下,离开按钮,进入按钮,鼠标弹起 事件,事件的个参数和系统类似事件参数一致
下面绿色是调用例子
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'使用例子
'Dim WithEvents a As PicCmd '声明使用自定义事件
'Private Sub a_vMouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
' Debug.Print "down"
'End Sub
'Private Sub a_vMouseOut(Button As Integer, Shift As Integer, x As Single, y As Single)
' Debug.Print "Out"
'End Sub
'Private Sub a_vMouseOver(Button As Integer, Shift As Integer, x As Single, y As Single)
' Debug.Print "over"
'End Sub
'Private Sub a_vMouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
' Debug.Print "MouseUp"
'End Sub
'Private Sub Command1_Click() 'Form,PictureBox为像素度量,设定的顺序如下,注意顺序
' Set a = New PicCmd
' Set a.picBox = pp 'pp是一个PictureBox控件
' Set a.picDown = LoadPicture(App.Path & "/down.jpg") '按下时的图片
' Set a.picOver = LoadPicture(App.Path & "/over.jpg") '鼠标经过时的图片
' Set a.picXX = LoadPicture(App.Path & "/xx.jpg") '按钮不可用时的图片
' Set a.picUp = LoadPicture(App.Path & "/up.jpg") '普通状态时的图片
' a.vEnabled = True
'End Sub
'Private Sub Command2_Click()
' a.vEnabled = Not a.vEnabled
'End Sub |
-
成品效果
-
VB设计器中的显示效果
-
-
图形按钮类示例.rar
42.69 KB, 下载次数: 162
类和VB调用示例
|