C# C移动/单击鼠标Winforms
我想制作一个应用程序,只需在后台按下一个按钮,即可自动移动鼠标并单击它。。我来自Sales and Inventory/HTML Shop网站编程,这是我第一次制作涉及控件的应用程序。请帮助我,因为我想提高我的编程技能。 这就是我想做的和我的想法。 *我将放置一个循环计数器,用于重复移动 1.获取当前光标的x/y,并将其保存到名为坐标点A的变量中 2.右键单击它并移动右下角的点B 3.等2秒钟 4.使用可变坐标移回第一个位置 5.结束循环重复C# C移动/单击鼠标Winforms,c#,winforms,mouse,C#,Winforms,Mouse,我想制作一个应用程序,只需在后台按下一个按钮,即可自动移动鼠标并单击它。。我来自Sales and Inventory/HTML Shop网站编程,这是我第一次制作涉及控件的应用程序。请帮助我,因为我想提高我的编程技能。 这就是我想做的和我的想法。 *我将放置一个循环计数器,用于重复移动 1.获取当前光标的x/y,并将其保存到名为坐标点A的变量中 2.右键单击它并移动右下角的点B 3.等2秒钟 4.使用可变坐标移回第一个位置 5.结束循环重复 这是我的想法和算法我的问题是我不知道如何移动鼠标并使
这是我的想法和算法我的问题是我不知道如何移动鼠标并使其停止。你可以移动鼠标,编写如下函数或代码:
private void MoveCursor()
{
// Set the Current cursor, move the cursor's Position,
// and set its clipping rectangle to the form.
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);
}
要查找窗体上任何控件的位置,可以使用以下代码
Point locationOnForm = control.FindForm().PointToClient(
control.Parent.PointToScreen(control.Location));
在要将光标移动到屏幕上特定点的窗口窗体项目中,可以使用此静态方法 System.Windows.Forms.Cursor.Position=新点X,Y 要执行单击事件,可以使用此方法
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
uint X = (uint)System.Windows.Forms.Cursor.Position.X;
uint Y = (uint)System.Windows.Forms.Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
水渍险?你是说WPF,对吗?在这种情况下,您有一个相关的答案woops抱歉,我的意思是Windows应用程序窗体严格地说,Windows应用程序窗体可以是winforms或wpf都是Windows应用程序并且有窗体。我想您的表单是winforms:-