Textbox text always selected by defualt?

Dartshark

New member
Joined
Feb 3, 2011
Messages
3
Location
Entiat, Wa
Programming Experience
10+
I created a form to capture a user name and password.
I thought it would be nice, during the form load event, for me to put the windows username in the name field for them in case they were the same.

When I do this the name appears selected/highlighted.
I didn't expect this to be the default but it seems to be.

I then use select(0, 0) to remove the selection I didn't want in the first place and try to move the focus down to the password field but it doesn't work.

Can someone tell me if the text being automatically selected is normal and why I can't change focus to the password field.

Yes I'm new to VB.

Private Sub CivilMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


txtUser.Text = (
Environment.UserName)
txtUser.Select(0, 0)
txtPassword.Focus()

End Sub
 
Give this a try:
VB.NET:
Private Sub CivilMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    txtUser.Text = Environment.UserName
End Sub

Private Sub CivilMain_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Shown
    txtPassword.Focus()
End Sub
 
Thanks for your help, I was wondering if I needed to find a way to change the focus after the load but before anything else happened but I hadn't found out how yet.
Now I know.

Have a great weekend :)
 
Back
Top