A couple of questions regarding TextBox

D

dln

Howdy. I'm a bit new to C# and got a couple of quick questions that perhaps
someone can help me answer. First, is there a property that you set on a
TextBox control that will force the control to accept only numerical data
(i.e. - only numbers 0 to 9, a decimal and the negative sign)? So far, I've
had to do the validation manually on either a key down or OnValidate event.
Secondly, is there any way to preview a key stroke for a given control and
then either accept or toss the value of the key stroke depending on some
sort of pre-defined rule? So for example, if a user were to enter hit the
"a" key while in a text box, what I would like to have happen is to have the
application eat the keystroke and not have the "a" character ever show up in
the text control. Is this possible? Any assistance provided would be
greatly appreciated.

Thanks.
 
D

dln

Great! Thanks for the reply.

Vijaye Raji said:
Handling the KeyDown event is the way to go.

When you find some key is invalid, set the Handled property on the
KeyPressEventArgs to true - the character will not appear on the text
control.

HTH
-vJ

up
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top