C# 如何在C中禁用鼠标单击# 努力实现
我试图在一定时间内阻止鼠标输入 我想使用如下代码:-C# 如何在C中禁用鼠标单击# 努力实现,c#,winforms,C#,Winforms,我试图在一定时间内阻止鼠标输入 我想使用如下代码:- BlockMouse(true); // My code starts here ... // My code ends here BlockMouse(false); 我试过了 BlockInput(true)但它需要提升权限 使用此代码并实现IMessageFilter Rectangle BoundRect; Rectangle OldRect = Rectangle.Empty; private void EnableMou
BlockMouse(true);
// My code starts here
...
// My code ends here
BlockMouse(false);
我试过了
但它需要提升权限BlockInput(true)
- 使用此代码并实现IMessageFilter
Rectangle BoundRect;
Rectangle OldRect = Rectangle.Empty;
private void EnableMouse()
{
Cursor.Clip = OldRect;
Cursor.Show();
Application.RemoveMessageFilter(this);
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
return false;
}
private void DisableMouse()
{
OldRect = Cursor.Clip;
// Arbitrary location.
BoundRect = new Rectangle(50, 50, 1, 1);
Cursor.Clip = BoundRect;
Cursor.Hide();
Application.AddMessageFilter(this);
}
我认为在代码运行时将所有控件(如按钮)设置为禁用,然后再次启用它们更为优雅 要向用户提供光学反馈,请将光标设置为忙于
Application.UseWaitCursor=true
然后Application.UseWaitCursor=false代码>
当然,此解决方案只会阻止应用程序上的鼠标单击,并且不会完全禁用鼠标单击我认为阻止鼠标单击并不好,因为大多数输入都是通过鼠标单击进行的,如果重写protected override void OnMouseDown(MouseEventArgs e)会更好
看一个低层鼠标挂钩。我对低层鼠标以及如何取消鼠标点击事件一无所知。如果你想做这件事,你应该解释一下。也许有一种更直接的方法可以达到相同的总体效果。@Jquey007也许这是值得研究的。。。以前也有人问过这个问题。好的,我的应用程序向其他应用程序发送信息,最后是发送回车按钮事件,这是一个很好的解决方案,但他从来没有说他只想停止对程序的点击,所以如果他想停止系统范围内的所有鼠标点击,这将不再有效。