【发布时间】:2013-07-30 10:31:40
【问题描述】:
我在 winform 的代码隐藏文件中执行此操作时遇到问题:
// Waiting Cursor + disabling form
Cursor = Cursors.WaitCursor;
this.Enabled = false;
// Synchronous method
SomeWork();
// Re-enabling form
Cursor = Cursors.Default;
this.Enabled = true;
当前行为
例如在Somework() 期间单击按钮将在重新启用表单后执行与按钮关联的方法。
预期行为
我不希望表单在禁用表单时存储用户的点击事件。
问题
有没有办法清空表单的点击缓存(这样我会在重新启用表单之前这样做)?
重要编辑
一个可能的简单解决方案是在表单后面的代码中实现IMessageFilter 接口。使用 PreFilterMessage 禁用左侧似乎很容易:
public bool PreFilterMessage(ref Message m)
{
// Blocks all the messages relating to the left mouse button.
return (m.Msg >= 513 && m.Msg <= 515) ;
}
但再一次,禁用和重新启用鼠标左键不会清空鼠标缓冲区 ...
【问题讨论】:
-
表单在禁用时无法接收任何点击消息。你确定吗?您能否提供有关您的演示的更多信息,例如您单击了哪个控件?...
标签: c# winforms caching mouseevent clicking