各位大虾好
小弟想写一个锁屏的程序
让鼠标和键盘事件只能在winform窗体中触发
并且鼠标移不出winform窗体
谢谢各位
小弟想写一个锁屏的程序
让鼠标和键盘事件只能在winform窗体中触发
并且鼠标移不出winform窗体
谢谢各位
------回答---------
------其他回答(20分)---------
http://www.codeproject.com/KB/cs/globalhook. asp x
用这个库,一般的钩子一个函数一行代码足以。
------其他回答(30分)---------
这个方法在鼠标狂甩的情况下无效。。。。
-
C# code
-
private void Form1_MouseMove(object sender, MouseEventArgs e) { Point p = this.Location; label1.Text = "form>>" + p.X.ToString() + " : " + p.Y.ToString(); Point t = new Point(e.X,e.Y); t = PointToScreen(t); label2.Text = "mouse>>" + t.X.ToString() + " : " + t.Y.ToString(); if (t.X <= p.X + 10 ) { Cursor.Position = new Point(p.X + 10, t.Y); } else if (t.Y <= p.Y + 30) { Cursor.Position = new Point(t.X, p.Y + 30); } else if (t.X >= p.X + this.Width - 10) { Cursor.Position = new Point(p.X + this.Width - 10, t.Y); } else if (t.Y >= p.Y + this.Height - 30) { Cursor.Position = new Point(t.X, p.Y + this.Height - 30); } }
------其他回答(5分)---------
Cursor.Clip = RectangleToScreen(DisplayRectangle);
------其他回答(5分)---------
没啥难度,挂钩desktop的窗口句柄,截获鼠标移动消息就行了,请问下楼主应用场景是什么?
------其他回答(10分)---------
-
C# code
-
Cursor.Clip = RectangleToScreen(DisplayRectangle);
------其他回答(30分)---------
方法1:
-
C# code
-
private const int wm_nchittest = 0x84; private const int htclient = 0x1; private const int htcaption = 0x2; protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case wm_nchittest: base.WndProc(ref m); if ((int)m.Result == htclient) m.Result = (IntPtr)htcaption; return; } base.WndProc(ref m); }
方法2:
-
C# code
-
private Point mouse_offset = new Point(0,0); private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.mouse_offset = new Point(-e.X,-e.Y); } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { Point mousepos = Control.MousePosition; mousepos.Offset(this.mouse_offset.X,this.mouse_offset.Y-SystemInformation.CaptionHeight); this.Location = mousepos; } }
-
20140414
判断鼠标是否在窗体范围内
http://bbs.csdn.net/topics/340153012
http://www.cnblogs.com/wangjixianyun/archive/2013/02/25/2931582.html
-
mousemove的处理
-
-
http://www.isstudy.com/cjc/2087_2.html
-
具体的例子,但是我这就是不行,郁闷
-
我靠我靠我靠我靠我靠靠靠靠靠
-
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.FormArchiveInput_MouseMove);
-
少写了第二句中的this,就因为这个错误,耽误了将近三个小时,时间就是这么浪费了,我靠靠靠靠