文件对话框双击行为

发布于 2024-08-27 04:26:56 字数 713 浏览 6 评论 0原文

在开发 WinForms 应用程序时,我发现了 OpenFileDialog 和 SaveFileDialog 控件中的错误。谷歌搜索发现了另一个人注意到了同样的问题,但没有提供解决方案或解决方法。您可以在以下位置查看此主题: http://bytes.com/topic/visual-basic-net/answers/389470-open-file-dialog-picturebox-click-event

我的窗体上有一个处理 MouseDown 事件的自定义控件。如果我在鼠标悬停在 FileDialog 控件上(显然,它们之间有对话框)时双击 FileDialog 控件中的文件,则会触发 MouseDown 事件。我不认为这是我的控件的问题,因为我之前提到的人注意到 PictureBox 控件会发生这种情况。看起来,即使在对话框上按下鼠标按钮(第二次单击打开文件),当对话框关闭时,事件也会传递到表单和我的控件。

我尝试在对话框处于活动状态时禁用控件,但这并没有阻止它捕获事件。我认为这是因为事件在对话框关闭后被传递,所以我的控件将被重新启用。有谁知道有什么方法可以防止点击到达表单,从而防止我的控制?另外,任何人都可以确认这是否确实是 FileDialog 控件中的错误,或者我只是配置了一些设置不正确?

While developing a WinForms application, I came across what I believe is a bug in the OpenFileDialog and SaveFileDialog controls. A Google search turned up a single other person who noticed the same issue, but neither a solution nor a workaround was provided. You can view this thread at: http://bytes.com/topic/visual-basic-net/answers/389470-open-file-dialog-picturebox-click-event.

I have a custom control on my form that handles the MouseDown event. If I doubleclick a file in a FileDialog control while the mouse is over this control (with the dialog between them, obviously), the MouseDown event gets triggered. I don't think this is an issue with my control, because the person I mentioned before noticed this happening with a PictureBox control. It would seem that even though the mouse button was pressed down (for the second click to open the file) while on the dialog box, the event passed through to the form and my control when the dialog closed.

I have tried disabling my control while the dialog box is active, but that didn't stop it from capturing the event. I assume this is because the event is passed down after the dialog closes, so my control would be re-enabled. Does anyone know of a way to prevent that click from reaching the form and, in turn, my control? Also, can anyone confirm if this really is a bug in the FileDialog controls, or if I just have some setting configured incorrectly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无名指的心愿 2024-09-03 04:26:56

我以前听说过这个问题,据我所知,这是一个确保正确处理事件队列的问题。在不查看代码的情况下,很难检查用户控件实现是否正确,但通常情况下,重写鼠标事件而不让基本事件也发生可能会导致这种行为。

I've heard of this problem before and as far as I know it's a matter of making sure that you handle the Event queue properly. Without seeing your code, it's very difficult to check that your user control implementation is correct but quite often, overriding the mouse events without letting the base events also occur can lead to this sort of behavior.

呆头 2024-09-03 04:26:56

当我意识到问题发生的原因时,我正在尝试 MouseDown 和 MouseMove 事件。当FileDialog框消失时,MouseMove事件被触发。为了避免两次编写相同的代码块(诚然愚蠢),我从 MouseMove 处理程序中调用 MouseDown 处理程序,认为某些条件(即没有按住鼠标按钮)会导致 MouseDown 处理程序有效地执行以下操作:没有什么。问题是鼠标按钮被按住,因为 FileDialog 框在 MouseDown(而不是 MouseClick)上消失。这导致 MouseDown 处理程序在我没有预料到的时候执行其条件代码。

从中吸取的教训是:在链接事件处理程序时要非常小心。或者更好的是,将通用功能放入方法中,并且永远不要链接事件处理程序。 :-)

感谢 Jelly Amma 给了我更仔细地观察实际事件的想法。

I was experimenting with the MouseDown and MouseMove events when I realized why my problem was occurring. When the FileDialog box disappeared, the MouseMove event was triggered. In an (admittedly silly) attempt to avoid writing the same block of code twice, I was calling my MouseDown handler from within the MouseMove handler, thinking that certain conditions (namely neither mouse button being held down) would cause the MouseDown handler to effectively do nothing. The issue was that the mouse button was being held down, because the FileDialog box disappears on MouseDown (not MouseClick). This caused the MouseDown handler to execute its conditional code when I wasn't expecting it.

Lesson to learn from this: be painfully careful when chaining event handlers. Or better, pull the common functionality into a method and NEVER chain event handlers. :-)

Thanks to Jelly Amma for giving me the idea to look at the actual events more closely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文