0

I have a component derived from DatagridView. I want to show a context menu when the user righ-click a cell. The problem is that the menu shows itself always at the origin of the screen, instead of the given coordinates.

My try:

this.MouseDown += HandleMouseDown;

private void HandleMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                var hti = HitTest(e.X, e.Y);
                if (hti.RowIndex >= 0)
                {
                    CurrentCell = this[hti.ColumnIndex, hti.RowIndex];
                    ContextMenuStrip menu = new ContextMenuStrip();
                    menu.Left = e.X;
                    menu.Top = e.Y;
                    menu.Items.Add("Aggiungi Pausa", null, HandleInsertPause);
                    menu.Items.Add("Rimuovi Pausa", null, HandleRemovePause);

                    menu.Show();
                }
            }
        }
user1238784
  • 2,250
  • 3
  • 22
  • 41

0 Answers0