Vb.net 上下文菜单问题
在列表框中有一些空白……在列表框中选择项目时,它会正确显示上下文菜单,但如果项目选择了项目并单击列表框中的任意位置,它会显示上下文菜单 我的要求是,在选择项目时,仅在选择项目的适当位置显示contexmenuVb.net 上下文菜单问题,vb.net,Vb.net,在列表框中有一些空白……在列表框中选择项目时,它会正确显示上下文菜单,但如果项目选择了项目并单击列表框中的任意位置,它会显示上下文菜单 我的要求是,在选择项目时,仅在选择项目的适当位置显示contexmenu 提前感谢……私有子LStreentDocs\u MouseUp\u 1(ByVal发送者作为系统。对象,ByVal e作为 System.Windows.Forms.MouseEventArgs)处理lstreentdocs.MouseUp Private Sub lstrecentdoc
提前感谢……私有子LStreentDocs\u MouseUp\u 1(ByVal发送者作为系统。对象,ByVal e作为 System.Windows.Forms.MouseEventArgs)处理lstreentdocs.MouseUp
Private Sub lstrecentdocs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstrecentdocs.SelectedIndexChanged
If lstrecentdocs.SelectedIndex = -1 Then
lstrecentdocs.ContextMenuStrip = Nothing
Else
lstrecentdocs.ContextMenuStrip = ContextMenuStrip2
End If
End Sub
Try
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim index = lstrecentdocs.IndexFromPoint(e.Location)
If index >= 0 Then
lstrecentdocs.SelectedIndex = index
ContextMenuStrip2.Show(lstrecentdocs, e.Location)
Else
ContextMenuStrip2.Visible = False
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub