如何控制鼠标,移动并悬停到某个控件上方?
如何控制鼠标,移动并悬停到某个控件上方?
如何移动鼠标到textbox上方?
------解决方案--------------------我不知道你说的上方是什么 是否是焦点?试下 TextBox1.Focus();
------解决方案--------------------问题1:
//锁定鼠标活动范围:
void LockCursor()
{
this.Cursor=new Cursor(Cursor.Current.Handle);
Cursor.Position=new Point(Cursor.Position.X,Cursor.Position.Y);
Cursor.Clip=new Rectangle(this.Location,this.size);//这里是窗体的大小.即鼠标只能在窗体范围内活动.如果要改成控件,只改动this.Location,this.size.
}
如果是,textBox txtbox:则:
void LockCursor()
{
this.Cursor=new Cursor(Cursor.Current.Handle);
Cursor.Position=new Point(Cursor.Position.X,Cursor.Position.Y);
Cursor.Clip=new Rectangle(txtbox.Location,txtbox.size);
}
希望对你有用!
------解决方案--------------------C# code
private void button1_Click(object sender, EventArgs e)
{
Point point = this.textBox1.PointToScreen(new Point(this.textBox1.Width / 2, this.textBox1.Height / 2));
Cursor.Position = point;
}