views:

80

answers:

3

This question seems to point to the existence of a windows event for a double-right-click. How to implement it in a C# windows form, however, is less than clear.

What's the best way to implement double-right-click on a control such as a button?

(I'm thinking I must use MouseDown and keep track of the time between clicks. Is there a better way?)

+5  A: 

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

That pinvoke page also has some C# sample code for how to do it.

Whenever you see something about a windows message and/or windows API and you want to use it in C#, the pinvoke site is a good place to start looking.

ho1
+3  A: 

Override Control.WndProc, and handle the WM_RBUTTONDBLCLK message manually.

Reed Copsey
A: 

I was able to implement this by inheriting from a button and overriding WndProc as ho1 and Reed suggested. Here's the inherited button:

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);
    }
}

I added the button programatically to the form and subscribed to its new DoubleRightClick event. I'm not sure how exactly to generate the appropriate MouseEventArgs but since this is just a test case, it's not important.

JYelton