How to implement double-click the right mouse button for winforms?

This question indicates the existence of a Windows event for double-clicking with the right mouse button. However, how to implement it in the form of a C # window is less than clear.

What is the best way to double-right-click on a control, such as a button?

(I think I should use MouseDown and keep track of the time between clicks. Is there a better way?)

+7
c # winforms mouseevent
source share
4 answers

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

On this pinvoke page, there is also a sample C # code for how to do this.

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

+5
source share

Override Control.WndProc and process WM_RBUTTONDBLCLK manually.

+3
source share

MouseEventArgs contains a 'Button' property that indicates which button was clicked. So you can just check this:

  private void MouseDoubleClickEventHandler(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { DoSomthing(); } else if (e.Button == MouseButtons.Right) { DoSomethingElse(); } } 
+2
source share

I was able to implement this by inheriting from the button and redefining WndProc as ho1 and Reed. 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 program to the form and subscribed to its new DoubleRightClick event. I'm not sure how to create the appropriate MouseEventArgs , but since this is just a test case, it doesn’t matter.

0
source share

All Articles