-2

Hey folks having issues finding any info on how I might remap the left click event in C# to be a right click event.

For example, everytime the user left clicks on a DataGrid in my application I want to be able to capture the left click and map it to a right click. So how do I simulate a right click every time the left click on the mouse is used. I've found some old .net2.0 examples where some C++ was ported over to C# to allow simulating clicks but I don't think it would be suitable and I don't truly understand what it was doing.

Any help appreciated. Thanks!

Keva
  • 13
  • 2
  • 7
    Don't take away my left clickin' – Sayse Jul 23 '13 at 11:46
  • 1
    _"capture the left click and map it to a right click"_ - I think you are interpreting or explaining your own problem wrong. Do you perhaps want to **show the context menu on left-click**? – CodeCaster Jul 23 '13 at 11:50
  • @CodeCaster Yes that is what I wish to do. – Keva Jul 23 '13 at 11:51
  • 1
    Then search for that. See [right click context menu for datagrid](http://stackoverflow.com/questions/1718389/right-click-context-menu-for-datagrid) for example. – CodeCaster Jul 23 '13 at 11:51
  • 2
    Thanks folks! From reading the link provided by @CodeCaster and the code snippet from Precious1tj I was able to get it sorted. Cheers! – Keva Jul 23 '13 at 12:08

2 Answers2

4

Just handle the mouse click event of the Datagrid

    private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            contextMenuStrip1.Show();
        }
        else if (e.Button == MouseButtons.Right)
        {
             //What you want it to do
        }
    }
0

When handling the event, check if it is a right click or a left one. No need to map the mouse clicks.

Noich
  • 14,631
  • 15
  • 62
  • 90