• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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?
0
Millkind
Asked:
Millkind
1 Solution
 
Fernando SotoCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now