Textbox and cursor placement after TextChanged

Posted on 2004-11-15
Last Modified: 2012-06-27
I have a sub that seems to work fine but after I do txtwhatever = txtwhatever & "-" it works but it places the cursor in the front of the textbox again which of course messes up the number if you are typing it straight in.
How can I format the text ie: "111-222-333" while the number is being entered without having the cursor placed at the front of the textbox after each event.

Private Sub txtFullSocial_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFullSocial.TextChanged
        If txtFullSocial.TextLength = 3 Then
            txtFullSocial.Text = txtFullSocial.Text & "-"
        ElseIf txtFullSocial.TextLength = 6 Then
            txtFullSocial.Text = txtFullSocial.Text & "-"
            Exit Sub
        End If
    End Sub
Question by:Matrix1000
    1 Comment
    LVL 34

    Accepted Solution

    Me.txtFullSocial.Select(Me.txtFullSocial.Text.Length, 1)

    after you finished "playing" with the text

    Seems to work for me :-)


    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

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now