need some help guys im trying to put a hyphen between a number for the telephone number but i want to use the keypress or textchanged i already done it using the button so im trying to use the textbox rightnow but after the hyphen is been inserted to a specific location it always go back to the starting point of the textbox.

Use a masked text box. Just set the mask and it will do the rest for you.

Example

tnx begg already solve it a while ago with browsing through the different thread in the forum

Try doing this (Formats the phone numbers to ###-###-####):

         Private Sub PhoneTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhoneTextBox.TextChanged
            If PhoneTextBox.TextLength = 3 Then
                PhoneTextBox.Text = PhoneTextBox.Text + "-"
                'Put the cursor after the last character
                PhoneTextBox.SelectionStart = Len(PhoneTextBox.Text)
            ElseIf PhoneTextBox.TextLength = 7 Then
                PhoneTextBox.Text = PhoneTextBox.Text + "-"
                PhoneTextBox.SelectionStart = Len(PhoneTextBox.Text)
            End If
        End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.