努力实现
我试图在一段时间内阻止鼠标输入
我想使用这样的代码:-
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);
}
关于c# - 如何在C#中禁用鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35757695/