无法设置上下文菜单条的位置?
我试图在右键单击鼠标的位置打开一个 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));
}
}
I'm trying to open a contextmenustrip
at the place where I right-clicked the mouse, but it always shows at top left of the screen.
Here is the code I used:
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));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它没有出现的原因是您使用 eX 和 eY 作为值。它们不是屏幕上的实际位置。它们是鼠标在数据网格中的位置。假设您单击了第一行的第一个单元格,该单元格将位于该组件的左上角附近。 eX 和 eY 是组件内的鼠标位置。
the reason it's not appearing is because you are using e.X and e.Y for the values. They are not the actual location on the screen. They are the location of the mouse within the datagrid. So say you clicked on the first cell of the first row, that will be near the top left of that component. e.X and e.Y are the mouse locations within the component.
假设您使用的是 Windows 窗体,请尝试以下操作:
assuming you are in Windows Forms, try this: