如何使鼠标冻结C# [英] how to Make the Mouse Freeze c#
本文介绍了如何使鼠标冻结C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想鼠标FREEZ(广东话移动)时,按下鼠标 谢谢
i want the mouse to freez (cant move) when mouse down thanks
推荐答案
我用一个TableLayoutPanel供大家参考(只记得落实code的控制是在前):
I used a tableLayoutPanel for your reference (Just remember to implement the code to the Control that is in the front):
选项1:复位鼠标位置:
定义两个全局变量:
bool mousemove = true;
Point currentp = new Point(0, 0);
亨德尔MouseDown事件来更新鼠标移动
:
private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
{
int offsetX = (sender as Control).Location.X + this.Location.X;
int offsetY = (sender as Control).Location.Y + this.Location.Y;
mousemove = false;
currentp = new Point(e.X+offsetX, e.Y+offsetY); //or just use Cursor.Position
}
亨德尔的MouseMove
禁用/启用招:
private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
{
if (!mousemove)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = currentp;
}
}
重置鼠标移动
,而鼠标松开
private void tableLayoutPanel1_MouseUp(object sender, MouseEventArgs e)
{
mousemove = true;
}
OPTION2:限制鼠标剪辑矩形:
限制它,而的MouseDown:
Limit it while MouseDown:
private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = Cursor.Position;
Cursor.Clip = new Rectangle(Cursor.Position, new Size(0, 0));
}
的MouseUp后释放它:
Release it after MouseUp:
private void tableLayoutPanel1_MouseUp(object sender, MouseEventArgs e)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = Cursor.Position;
Cursor.Clip = Screen.PrimaryScreen.Bounds;
}
这篇关于如何使鼠标冻结C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文