<分区>
在我的 Windows 应用程序中,我想隐藏和禁用任何鼠标移动,因为我是在我的应用程序中处理它的。我可以将光标的位置设置为一个点,但如果用户移动鼠标,它就会改变位置。
如何阻止用户输入移动鼠标?
<分区>
在我的 Windows 应用程序中,我想隐藏和禁用任何鼠标移动,因为我是在我的应用程序中处理它的。我可以将光标的位置设置为一个点,但如果用户移动鼠标,它就会改变位置。
如何阻止用户输入移动鼠标?
最佳答案
让您的表单实现 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/8970845/