Move your mouse to where you click the C # button

This is my first post, and I tried to find a solution, but to no avail.

I am trying to move the mouse cursor by clicking a tab button. i.e. tab selects the next field to select, and I want my mouse to be in this selectable field so that the mouse moves around the page by clicking on the tab.

Otherwise, the method of obtaining the selected elements coordinates and assigns the same mouse.

- Deletion of information not specified -

My program opens another program, and I'm not sure how to refer to the selected elements of this program in which the problem occurs.

Thank.

+4
source share
1 answer

Adding this event handler to your form:

private void control_Enter(object sender, EventArgs e)
{
    if (sender is Control)
    {
        var control = (Control)sender;
        Cursor.Position = control.PointToScreen(new Point()
        {
            X = control.Width / 2,
            Y = control.Height / 2
        });
    }
}

, , "" , :

button1.Enter += control_Enter;

, , .

, , . , .


, :

, , :

void SubscribeControlsOnEnter(Form form)
{
    foreach (Control control in form.Controls)
    {
        control.Enter += control_Enter;
    }
}

, . , , , .

(, Form Control):

void SubscribeNestedControlsOnEnter(Control container)
{
    foreach (Control control in container.Controls)
    {
        if (control.Controls.Count > 0)
        {
            SubscribeNestedControlsOnEnter(control);
        }
        else control.Enter += control_Enter;
    }
}

:

Form1 form = new Form1();
SubscribeNestedControlsOnEnter(form);
form.Show();
+3

All Articles