How to set cursor focus to a TextBox?
I have a window pop up with a TextBox and would like to focus the cursor to it. So a user can directly type text.
I could not find a proper property. Is there one?
How to set cursor focus to a TextBox?
I have a window pop up with a TextBox and would like to focus the cursor to it. So a user can directly type text.
I could not find a proper property. Is there one?
To set focus on a textbox when your form loads you can do this:
private void Form_Load(object sender, EventArgs e)
{
SomeTextBox.Select();
}
Note** You have to put it within the Form_Load event.
In WPF, try this:
FocusManager.SetFocusedElement(parentElement, txtMyTextBox)
Read more about FocusManager.SetFocusedElement here.
OR
txtMyTextBox.Focusable = true;
Keyboard.Focus(txtMyTextBox);