Not sure why this question was generous, the accepted answer should already be pretty close to a solution. Except that you should use MouseUp instead of MouseDown, your user usually expects the click action to take effect when he releases the button. Which provides a backup of "oops does not mean that you need to click on it, move the mouse so that it is ignored."
However, for built-in Winforms controls, such as PictureBox, this is configured using the Control.SetStyle () method. Add a new class to your project and paste the code shown below. Compilation. Drop the new control on top of the toolbar:
using System; using System.Windows.Forms; class MyPictureBox : PictureBox { public MyPictureBox() { this.SetStyle(ControlStyles.StandardDoubleClick, false); } }
However, be careful that this does not work for .NET classes that wrap an existing native Windows control. Like TextBox, ListBox, TreeView, etc. This configuration is based on the WNDCLASSEX.style element, a CS_DBLCLKS style flag. Code that sets the style flag is baked on Windows and cannot be changed. You will need a different type of operation to double-click with one click. You can do this by overriding the WndProc () method, I will give an example for a TextBox:
using System; using System.Windows.Forms; class MyTextBox : TextBox { protected override void WndProc(ref Message m) {
Just change the class name if you want to do this for other controls. Commandeering Winforms, to make it work the way you want, never takes up a lot of code, just Petzold :)
source share