programnub
programnub

Reputation: 85

Using Double Right Click in C#

I am fairly new with C# and I want to know if there is a way to implement a double right click in this event handler? Can anyone tell me how? thanks

private void pictureBox_MouseClick(object sender, MouseEventArgs e){
    if(e.Button == MouseButtons.Left)
    {
       MessageBox.Show("A");
    }
    else if(e.Button = MouseButtons.Right)
    {
       MessageBox.Show("B");
    }
    else if(e.Button = MouseDoubleClick.Right) <--how to fix this?
    {
       MessageBox.Show("C");
    }
    else
    {
        MessageBox.Show("D");
    }
}

Upvotes: 1

Views: 1213

Answers (2)

DisplayName
DisplayName

Reputation: 71

Override the WndProc function and listen for WM_RBUTTONDBLCLK, which as can be seen on this pinvoke page is {0x0206}.

Then

public class RButton : Button
{
    public delegate void MouseDoubleRightClick(object sender, MouseEventArgs e);
    public event MouseDoubleRightClick DoubleRightClick;
    protected override void WndProc(ref Message m)
    {
        const Int32 WM_RBUTTONDBLCLK = 0x0206;
        if (m.Msg == WM_RBUTTONDBLCLK)
            DoubleRightClick(this, null);
        base.WndProc(ref m);
    }
}

Upvotes: 0

Afnan Ahmad
Afnan Ahmad

Reputation: 2542

You can use the ClickCount propery of MouseRightButtonDown event.

private void OnMouseDownClickCount(object sender, MouseButtonEventArgs e)
{
    if (e.ClickCount == 1)
    {
        // one click.
    }
    if (e.ClickCount == 2)
    {
        // two clicks.
    }
} 

Upvotes: 3

Related Questions