如何将鼠标移动到表单上的特定按钮 [英] How do I move a mouse to specific button on the form

查看:69
本文介绍了如何将鼠标移动到表单上的特定按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试自动移动鼠标并按下表单上的按钮但我部分成功。



到目前为止这是我的剧本。



声明如下:

Hi all,

I am trying to automate a move of a mouse and press a button on the form but I am partially successful.

So far this is my script.

Declarations are:

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] // This declaration and following objects must be grouped together
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int MOUSEEVENTF_MOVE = 0x0001; /* mouse move */
private const int MOUSEEVENTF_LEFTDOWN = 0x0002; /* left button down */
private const int MOUSEEVENTF_LEFTUP = 0x0004; /* left button up */





鼠标事件代码为:





And the mouse event code is:

public void DoMouseClick_Event()
        {
            int X = this.btn_Next.Location.X;
            int Y = this.btn_Next.Location.Y;

            mouse_event((int)MOUSEEVENTF_MOVE, X, Y, 0, 0);
            mouse_event((int)MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        } // Mouse event





值X和Y获取表单上按钮btn_Next的位置。然后鼠标事件执行移动到所述位置并按下按钮。现在我知道移动和按钮事件有效,但是在窗体上获取按钮的位置不能正常工作,因为鼠标在按钮附近没有移动。



如何准确获取表单上按钮的位置,然后将鼠标移动到那里?



Values X and Y acquire the location of the button "btn_Next" on the form. Then the mouse event executes the move to the said location and presses the button. Now I know that the move and press button event works, but getting the location of the button on the form is not working so well as the mouse moves no where near the button.

How do I accurately get the location of the button on the form and then move the mouse there?

推荐答案

尝试以编程方式移动鼠标指针 [ ^ ]。这解释了以编程方式将鼠标移动到按钮的中心。
Try Moving the Mouse Pointer Programmatically[^]. This explains moving the mouse to the center of a button programmatically.


这篇关于如何将鼠标移动到表单上的特定按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆