What code should be used to focus on a TextBox?
I am creating a system, where it is necessary that when the client press ESC, the focus of the textBox is lost.
How do I do it?
What code should be used to focus on a TextBox?
I am creating a system, where it is necessary that when the client press ESC, the focus of the textBox is lost.
How do I do it?
You can do this in two ways:
It is also possible to change the active control from form to null
.
this.ActiveControl = null;
You need some other focusable control
so you can change the focus, you can set to label
, for example:
private void key_pressed(object sender, KeyPressed e)
{
this.ActiveControl = label1;
}
or to a NULL
private void key_pressed(object sender, KeyPressed e)
{
this.ActiveControl = NULL;
}