c#如何让鼠标不能点击
- 提问者网友:兔牙战士
- 2021-02-10 03:09
- 五星知识达人网友:鱼忧
- 2021-02-10 03:53
public bool PreFilterMessage(ref System.Windows.Forms.Message SystemMessage)
{
if (SystemMessage.Msg >= 513 && SystemMessage.Msg <= 515)
{//不响应鼠标左键消息
return true;
}
return false;
}
//调用
Application.AddMessageFilter(this);
- 1楼网友:人類模型
- 2021-02-10 05:09
调用user32.dll中的setcursorpos以及mouse_event函数,我试了一下,完全能实现你想要的功能。
//声明两个函数
[system.runtime.interopservices.dllimport("user32.dll")] static extern bool setcursorpos(int x, int y); [system.runtime.interopservices.dllimport("user32.dll")] static extern void mouse_event(mouseeventflag flags, int dx, int dy, uint data, uintptr extrainfo); [flags] enum mouseeventflag : uint { move = 0x0001, leftdown = 0x0002, leftup = 0x0004, rightdown = 0x0008, rightup = 0x0010, middledown = 0x0020, middleup = 0x0040, xdown = 0x0080, xup = 0x0100, wheel = 0x0800, virtualdesk = 0x4000, absolute = 0x8000 }
//在timer事件中添加如下代码就ok了
//将鼠标移到指定坐标
setcursorpos(400, 300);
//按下左键 mouse_event(mouseeventflag.leftdown , 0, 0, 0,uintptr.zero );
//释放左键 mouse_event(mouseeventflag.leftup , 0, 0, 0, uintptr.zero);
搞不定,可以加我qq。