-My code sutomatically adds a hyphen at certain positions in the string, but I am unable to delete the second hyphen if I want to edit what I've typed in before that. Is there a way to fix this?

Private Sub txtISBN_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtISBN.KeyPress
        If txtISBN.TextLength = 1 Then
        txtISBN.Text = txtISBN.Text + "-"
        txtISBN.SelectionStart = Len(txtISBN.Text)
    Else
        If txtISBN.TextLength = 9 Then
        txtISBN.Text = txtISBN.Text + "-"
        txtISBN.SelectionStart = Len(txtISBN.Text)
    Else
        If txtISBN.TextLength = 11 Then
        txtISBN.Text = txtISBN.Text + "-"
        txtISBN.SelectionStart = Len(txtISBN.Text)
    End If
    End If
    End If
End Sub
End Class

Recommended Answers

All 2 Replies

I think what you are looking for is a Masked Text Box.

If you prefer to use textbox, here.

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.