FileDialog DoubleClick Behavior

When developing a WinForms application, I came across what, in my opinion, is an error in the OpenFileDialog and SaveFileDialog elements. Another person appeared on a Google search who noticed the same problem, but no solution or workaround was provided. You can view this topic: http://bytes.com/topic/visual-basic-net/answers/389470-open-file-dialog-picturebox-click-event .

I have a custom control in my form that handles the MouseDown event. If I double-clicked a file in a FileDialog control when the mouse is over this control (obviously, with a dialog between them), the MouseDown event is fired. I don’t think this is a problem with my control because the person I mentioned noticed that this is happening with the PictureBox control. It would seem that although the mouse button was pressed (for a second click to open the file), while in the dialog the event passed through the form and my control when the dialog is closed.

I tried to disable my control while the dialog was active, but that did not stop it from capturing the event. I assume this is because the event is dispatched after the dialog box closes, so my control will be turned back on. Does anyone know how to prevent this click from getting into the form and, in turn, my control? Also, can anyone confirm if this is really a bug in the FileDialog elements, or if I have an incorrect setting?

+6
c # winforms mouseevent filedialog double-click
source share
2 answers

I experimented with the MouseDown and MouseMove events when I realized why my problem arose. When the FileDialog field disappeared, the MouseMove event was fired. In a (admittedly stupid) attempt to avoid writing the same block of code twice, I called my MouseDown handler from the MouseMove handler, believing that certain conditions (namely, no mouse buttons are held down) can cause the MouseDown handler to effectively do anything . The problem was that the mouse button was pressed because the FileDialog field disappears on MouseDown (not MouseClick). This caused the MouseDown handler to execute its conditional code when I did not expect this.

A lesson to learn from this: be careful when binding event handlers. Or better, pull the general functionality into a method and never execute event handlers. :-)

Thanks to Jelly Amma for giving me the opportunity to more closely examine actual events.

+1
source share

I have heard about this problem before, and as far as I know, it is important that you handle the event queue correctly. Without viewing the code, it is very difficult to verify the correct implementation of user control, but quite often redefinition of mouse events, avoiding the occurrence of basic events, can lead to this behavior.

+3
source share

All Articles