加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb2008弹出菜单位置

发布时间:2020-12-17 07:40:55 所属栏目:百科 来源:网络整理
导读:vb2008 中大多控件的位置可以使用location 属性来控制,但是 ContextMenuStrip这个控件偏偏不支持这个属性 Location Infrastructure. This property is not relevant to this class. (Inherited from ToolStripDropDown .) 那么怎么办呢,可以用ContextMenuS

vb2008 中大多控件的位置可以使用location 属性来控制,但是 ContextMenuStrip这个控件偏偏不支持这个属性

Location Infrastructure. This property is not relevant to this class. (Inherited from ToolStripDropDown.)

那么怎么办呢,可以用ContextMenuStrip.show()这个方法来实现,在其中加入具体位置即可(point),比如鼠标的位置。

以下是一个示例,只需要建立一个空白窗体即可,弹出菜单直接用代码完成了(也可以直接在可视化界面里直接拉一个,然后设置好)。

Private Sub Form1_MouseDown(ByVal sender As System.Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown '监听鼠标按下事件
If e.Button = Windows.Forms.MouseButtons.Right Then '是鼠标右键按下事件

Dim mnu As ContextMenuStrip = New Windows.Forms.ContextMenuStrip ’新建个ContextMenuStrip 控件
Dim submnu1 As ToolStripMenuItem = mnu.Items.Add("弹出菜单1")'添加子菜单1
Dim submnu2 As ToolStripMenuItem = mnu.Items.Add("弹出菜单2") '添加子菜单2

Dim mousePoint As Point = New System.Drawing.Point(e.Location) '获取鼠标位置信息
mnu.Show(mousePoint) ‘显示弹出菜单

End If
End Sub

效果如下图,是不是很简单,你也行的哦!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读