Set Focus to Last thing used

I have five text boxes and two buttons your typing along in the first textbox and realize you need to click one of the buttons.  After you click the button you want the focus to be on the last box you were working in.  How do I do that?
MillkindAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi Millkind;

This will do what you want.

    Private LastTextBox As TextBox

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        ' Do what ever in the Button event
        LastTextBox.Focus()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click

        ' Do what ever in the Button event
        LastTextBox.Focus()

    End Sub

    Private Sub TextBox_LostFocus(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles TextBox1.LostFocus, TextBox2.LostFocus, _
        TextBox3.LostFocus, TextBox4.LostFocus, TextBox5.LostFocus

        LastTextBox = CType(sender, TextBox)

    End Sub


Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.