如何在鼠标单击时找到上下文菜单条的位置 [英] how to locate the position of a context menu strip on mouse click

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

问题描述

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

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

推荐答案

通常相对于特定控件显示 - 它只是抵消它的情况(如果你愿意)通过手动构建它并使用Show方法从相关控件的左上角开始一个数量:MSDN有一个例子: http://msdn.microsoft.com/en-us/library/s00cc2f3.aspx [ ^ ]
It is normally shown relative to a particular control - it's just a case of offsetting it (if you want to) by an amount from the top left hand corner of the relevant control by manually constructing it and using the Show method: MSDN has an example: http://msdn.microsoft.com/en-us/library/s00cc2f3.aspx[^]


这应该可以解决问题...
This should do the trick...
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)


DataGridView



In DataGridView

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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆