ConTextMenuStrip控件不要和listbox绑定,用代码弹出来:
成都创新互联公司-企业级云服务器提供商,为用户提供云服务器、CDN、云安全服务、服务器托管、服务器租用、高防服务器等全方位云服务与各行业解决方案,帮助企业及个人极速备案,轻松上云,安全无忧。
Private Sub ListBoxUser_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBoxUser.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim sPoint As Point = New Point(e.X, e.Y)
Dim sIndex As Integer = ListBoxUser.IndexFromPoint(sPoint.X, sPoint.Y)
If sIndex -1 Then
ListBoxUser.SelectedIndex = sIndex
ListBoxUser.ContextMenuStrip = ContextMenuListBox
Else
ListBoxUser.ContextMenuStrip = Nothing
End If
Else
ListBoxUser.ContextMenuStrip = Nothing
End If
End Sub
上面示例中,ListBoxUser是一个ListBox实例,ContextMenuListBox是一个菜单示例。
添加一个ContextMenuStrip,设计好菜单后,点你要弹出这个菜单的控件,将ContextMenu属性改成你要的菜单
如果是窗体右键单击事件,是
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
'这里写你要的代码
End If
End Sub
但是如果只是右键单击就弹出菜单的话没必要这样,只需要在窗体上放置一个ContextMenuStrip控件,然后在Form的ContextMenuStrip属性中绑定这个控件就可以了。
当前名称:vb.net的右键控件 vb 选项按钮
路径分享:https://www.cdcxhl.com/article14/hpooge.html
成都网站建设公司_创新互联,为您提供企业建站、移动网站建设、企业网站制作、Google、云服务器、网站内链
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联