无法设置contextmenustrip的位置?

Tar*_*fih 9 c# contextmenustrip winforms

我正试图contextmenustrip在我右键单击鼠标的地方打开一个,但它总是显示在屏幕的左上角.

这是我使用的代码:

private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        contextMenuStrip1.Show(new Point(e.X,e.Y));
        doss.getdossier(connection.conn, Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value));
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 11

if (e.Button == MouseButtons.Right)
{
    contextMenuStrip1.Show(Cursor.Position);
}
Run Code Online (Sandbox Code Playgroud)

它没有出现的原因是因为你使用eX和eY作为值.它们不是屏幕上的实际位置.它们是数据网格中鼠标的位置.所以说你点击了第一行的第一个单元格,它将靠近该组件的左上角.eX和eY是组件中的鼠标位置.