textbox focus

knappster

Active member
Joined
Nov 13, 2006
Messages
42
Programming Experience
Beginner
Hi, I have a textbox on a form and I want to set the focus to that textbox when the form loads. In the forms load event I put the following

VB.NET:
txtFirstName.Focus()

but when I run the form the textbox doesn't have focus! Does anyone know why this is happening. The textbox is within a groupbox which is within a panel but this shouldn't matter should it??
 
The best thing would be to set TabIndex for all your focusable controls in appropriate order, where the first has index 0.

About the Focus method, it doesn't work before form is shown and Load event happens before that, it would work in Shown event.
 
Back
Top