Nay Win Tun
Nay Win Tun

Reputation: 1

Why in every right click, the context menustrip pop up,how to enable it in a specify position by controlling the right click event?

Why in every right click, the contextmenustrip pop up,how to enable it in a specify position by controlling the right click event??

Upvotes: 0

Views: 33

Answers (1)

programmer444
programmer444

Reputation: 156

Try to remove the default contextmenustrip and create a new one. With HitTest on a control you can check if the clicked position is on a element

 private void MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            if (dataGrid.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.ColumnHeader)
            {
                new ContextMenuStrip().Show(dataGrid, e.Location);
            }
        }
    }

See: How do I correctly position a Context Menu when I right click a DataGridView's column header?

Upvotes: 1

Related Questions