开发全自动液体工作站的过程,需要用到点击扩展菜单功能,经过摸索终于实现了一个Demo,现分享出来。
1、扩展菜单大致原理:利用PopUpMenu功能,事先做好扩展菜单以及子菜单,设置为隐藏属性,通过一定条件触发显示。
2、源码如下,供参考。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
''程序功能说明:利用PopupMenu功能实现窗体右键扩展菜单以及按钮按下扩展菜单功能
''
''程序开发时间:20170929
''
''软件版权信息:
''
''作者联系方式:参见博客地址
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'右键按下触发扩展菜单
Private Sub Form_MouseDown(button As Integer, Shift As Integer, X As Single, Y As Single)
'利用PopupMenu方法
If button And vbRightButton Then
PopupMenu ButtonMenu '弹出菜单
End If
End Sub
'按钮点击触发弹出扩展菜单
Private Sub button_Click()
PopupMenu ButtonMenu '弹出菜单
End Sub
Private Sub ButtonBlack_Click()
Shape1.BackStyle = 1
Shape1.BackColor = vbBlack
End Sub
Private Sub ButtonGreen_Click()
Shape1.BackStyle = 1
Shape1.BackColor = vbGreen
End Sub
Private Sub ButtonRed_Click()
Shape1.BackStyle = 1
Shape1.BackColor = vbRed
End Sub
Private Sub ButtonYellow_Click()
Shape1.BackStyle = 1
Shape1.BackColor = vbYellow
End Sub
3、Demo效果图。
4、实际测试效果视频。
链接:http://pan.baidu.com/s/1gfiYklt 密码:zgd5