我試圖從鼠標一定時間內阻止輸入我沒有成功如何在C#中禁用鼠標點擊
我試圖
塊引用
了BlockInput(真)但它需要提升的權限沒有用
這是我想要的
BlockMouse(true);
// My code starts here
...
// My code ends here
BlockMouse(false);
我試圖從鼠標一定時間內阻止輸入我沒有成功如何在C#中禁用鼠標點擊
我試圖
塊引用
了BlockInput(真)但它需要提升的權限沒有用
這是我想要的
BlockMouse(true);
// My code starts here
...
// My code ends here
BlockMouse(false);
使用此代碼,並實現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;
當然該溶液僅塊對應用程序的鼠標點擊和不完全禁用鼠標點擊
這是一個很好的解決方案,但他從不說他只想停止點擊他的程序,所以如果他想停止系統全部的鼠標點擊,這不再有效。 – Jacobr365
看一下低級別的鼠標鉤子。 – Jacobr365
我對低級鼠標以及如何取消鼠標單擊事件沒有任何意見 – Jquey007
也許你應該解釋一下你爲什麼要這樣做。可能有更直接的方法來達到相同的整體效果。 –