找到上下文菜单条的位置

找到上下文菜单条的位置

本文介绍了如何在鼠标单击时找到上下文菜单条的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在鼠标单击上找到上下文菜单条的位置

how to locate the position of a context menu strip on mouse click

推荐答案


Me.ContextMenuStrip1.Bounds.Location







Private Sub Form1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDoubleClick
        Me.ContextMenuStrip1.Show(MousePosition)
    End Sub

    Private Sub TestToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles TestToolStripMenuItem.Click
        MessageBox.Show(Me.ContextMenuStrip1.Bounds.Location.X & "x" & Me.ContextMenuStrip1.Bounds.Location.Y & _
                        vbCrLf & MousePosition.X & "x" & MousePosition.Y)


Private Sub YourDataGrid_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles YourDataGrid.CellMouseDown
        If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex >= 0 Then
            YourDataGrid.Rows(e.RowIndex).Selected = True
            'if possible insert code here to read selected option from context menu and get relevant content from respective cell

            YourContextMenu.Show(MousePosition.X, MousePosition.Y)
        End If
    End Sub


这篇关于如何在鼠标单击时找到上下文菜单条的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:06