Hi friends,
I wanted to restrict my text box to have only 10 characters.I have used the following code
Private Sub txtSpouseWorkPhone_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSpouseWorkPhone.KeyDown
If txtSpouseWorkPhone.TextLength > 10 Then
MsgBox("Only 10 characters are alowed", MsgBoxStyle.Critical, "Invalid PAN No")
txtSpouseWorkPhone.Text = txtSpouseWorkPhone.Text.Substring(0, (txtSpouseWorkPhone.TextLength - 1))
txtSpouseWorkPhone.Focus()
End If
But I have a small problem ie.
once the focus leaves the text box,I am not able to make further chances in it.ie.the message box appears irrespective of the keys we press, after 10 characters.