MouseEventArgs and Screen Position
-
I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:
private void PlayList_CellClick(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point loc = this.PointToScreen(new Point(e.X, e.Y));int index = PlayList.HitTest(e.X, e.Y).RowIndex; PlayListMenu.Show(loc.X, loc.Y); } }
It almost works, the context menu just doesn't popup in the right place. Any ideas?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
-
I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:
private void PlayList_CellClick(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point loc = this.PointToScreen(new Point(e.X, e.Y));int index = PlayList.HitTest(e.X, e.Y).RowIndex; PlayListMenu.Show(loc.X, loc.Y); } }
It almost works, the context menu just doesn't popup in the right place. Any ideas?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
I got it to work like this:
private void PlayList_CellClick(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point loc = new Point(e.X, e.Y + PlayList.ColumnHeadersHeight + (PlayList.Rows[0].Height * e.RowIndex));PlayListMenu.Show(PlayList, loc); } }
Is there a better way? Know of the right way?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
-
I have a form with a DataGridView on it. I have an event handler for the MouseUp event. I am trying to make a context menu popup on a right mouse click only, and appear right under the mouse. Here is what I have so far:
private void PlayList_CellClick(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point loc = this.PointToScreen(new Point(e.X, e.Y));int index = PlayList.HitTest(e.X, e.Y).RowIndex; PlayListMenu.Show(loc.X, loc.Y); } }
It almost works, the context menu just doesn't popup in the right place. Any ideas?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo