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();