i am very very new to C# and although i am used to VB 6 and a bit of C++ andJava .. i cant seem to find how to control the inputs on a text field.
i need a filter for my textbox that only accepts alpha numeric input.
i was thinking over the line of having a keypress event and checking at textbox_change that each char is alphanumeric. how to do this. plz can anyone give me a skeleton or the textbox_TextChanged function!
I am using Framework 1.1 i think thats why i dont even have the maskedtextbox commponent to help me :-P..
plz reply asap!
thanks...

keypress style for alphanumeric textbox help plz
JasonBSteele
hi nitin hope u still around to answer one more of my stupid Qs.
its saying :
System.Windows.Forms.KeyPressEventArgs' does not contain a definition for 'cancel'
help!
how can i get it to work
-Ankur
jrcran
1) Select the TextBox in designer view by clicking on it with your mouse.
2) Press F4 to view the properties of the control.
3) U'll see a lightning bolt symbol on top left corner. Click on that, it will display the events for the control.
4) In the events select the KeyPress event and double click on it. The thing is whenever you want to subscribe to an event you need to register it first. If you just copy paste the code that I have given it will not work since the event has not been registered till now. Double clicking on the event will also register it and provide you with a stub of that event.
Note: In the form in which you have placed the control(textbox) KeyPreview property should be set to true.
Regards,
Nitin
TPelkmans
u can use the following code
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsLetterOrDigit(e.KeyChar) == true ||(e.KeyChar)==8))
{
e.cancel = true;
}
Regards,
Nitin
venky_m
hi,
thanks guys for the reply but the prob has not yet been solved.
ok firstly i could not find the events property of the textbox. :-S
and secondly! if i copy and paste the code as u guys have given it... (changing the textbox's name as per the name i have) still when i run the file.. nothing happens.. i tried checking if the textbox1_keyPress function runs but i don't think it is running it. help guys..
thanks for the replies.
. i am online only! so if u guys around and wana ask more i will be here to provide..
Mahavir
Thanks man! yeah i found it! my mistake
I knew what u were talking about but completely forgot about the lightning thing. cause today is the first time i am using C# or any other .NET .
U a charm!.
Its working nicely!.
Cheers..
-Ankur
TonyMan - MSFT
Create a new event for your textbox (in properties window, select events, then search the Keypress and doubleclick there)
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 'a') this.label1.Text = this.textBox1.Text;
}