Set Focus to Last thing used

Posted on 2006-05-24
Last Modified: 2010-04-23
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?
Question by:Millkind
    1 Comment
    LVL 62

    Accepted Solution

    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

        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

        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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now