user944591
user944591

Reputation: 69

how to focus a specific textbox in vb.net

I'm making a desktop application in vb.net. When I click the back button (placed by me) on any form it hides current form and shows previous form but when i go again to the form from which i had hit back button then the focus cue still remains on the back button but I want the focus to be on the first textbox on that form or any specific button on which I want.....How can i achieve this...

I have already used some code to shift focus from one textbox to another when i press enter key...but it doesn't work in the above mentioned case....I'm using vb.net in visual studio 2005...

This is the code i'm using for shifting focus among textboxes

Private Sub party_code_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles party_code.KeyDown
    If e.KeyData = Keys.Return Then
        party_name.Focus()
    End If
End Sub

Can anyone help me on this????

Upvotes: 2

Views: 19583

Answers (1)

competent_tech
competent_tech

Reputation: 44921

You need to add a handler for either the form's Activated event:

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    party_name.Focus()
End Sub

Upvotes: 5

Related Questions