Formatting TextBox ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hell
I have a few text boxes on my form and I need in one to allow only numbers and on the other only letters how to enforce that you can't enter numbers in a letters textbox and...
Jack
 
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If Char.IsLetter(e.KeyChar) Then

'OK

Else

'Not OK

e.Handled = True

End If

End Sub

OHM





Jack said:
Hello
I have a few text boxes on my form and I need in one to allow only numbers
and on the other only letters how to enforce that you can't enter numbers in
a letters textbox and...
 
* "=?Utf-8?B?SmFjaw==?= said:
I have a few text boxes on my form and I need in one to allow only
numbers and on the other only letters how to enforce that you can't
enter numbers in a letters textbox and...

Instead of resticting the type of input, I would add code to the
control's 'Validating' event and set an ErrorProvider to make the user
aware of the invalid input. That's more user-friendly because you do
not forbid the user to do editing pasted text from the clipboard
etc. inside the textboxes.
 
granted!



Herfried K. Wagner said:
Instead of resticting the type of input, I would add code to the
control's 'Validating' event and set an ErrorProvider to make the user
aware of the invalid input. That's more user-friendly because you do
not forbid the user to do editing pasted text from the clipboard
etc. inside the textboxes.
 
Hi Jack,

I would take that nice piece of code from OHM and that what Herfried stated.

I think it is nicer that a user gets direct a signal when he is typing and
not after he had done a lot.

If you take the validate than, you prevent than all other things in one
time.

Just my thought

Cor
 
Back
Top