日期:2014-05-19  浏览次数:21061 次

C# 如何将鼠标移到指定的位置 比如e.x == 125,e.y == 1
谢谢各位,帮我解决一下吧?我没有查到!

------解决方案--------------------
.NET Framework 类库
Cursor.Position 属性
获取或设置光标位置。

属性值
代表光标位置的 Point(采用屏幕坐标)。

下面的代码示例从 Current 光标的 Handle 中创建光标,并更改其位置和剪辑矩形。结果是光标从执行代码时它所在的位置向左上方移动 50 个像素。另外,光标的剪辑矩形将更改到窗体的边界(默认情况下,为用户的整个屏幕)。此示例要求在单击时有可以调用这段代码的 Form 和 Button。

private void MoveCursor()
{
// If the form 's cursor is not the Default cursor,
// set the Current cursor, move the cursor 's Position,
// and set its clipping rectangle to the form.
if(!this.Cursor.Equals(Cursors.Default))
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
}
------解决方案--------------------
private void listBox1_MouseMove(object sender, MouseEventArgs e)
{
Cursor.Position = new Point(248, 0);
}