What code should be used to focus a Textbox?

Asked

Viewed 836 times

4

What code should be used to focus a Textbox?

I am creating a system, where I need that when the client keystrokes ESC, the focus of the textbox is lost.

How do I do?

  • 1

    would that you want: textbox.Focused = false; ?

  • no, the property Focused It’s read-only, I can’t change it

2 answers

6

You need some other focusable control to change the Focus, you can set to a label, for example:

private void key_pressed(object sender, KeyPressed e)  
{ 
  this.ActiveControl = label1;       
}

or for a NULL

private void key_pressed(object sender, KeyPressed e)  
{ 
  this.ActiveControl = NULL;       
}

4


It is possible to do this two ways:

  1. Change focus to a label, for example, since this does not remain user-friendly.
    In my view, this is the best idea because it makes it possible to choose the next control that will receive focus when clicking Tab    .
  1. It is also possible to change the active control of the form for null.

    this.ActiveControl = null;
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.