hi guys,
how could I disable letters and special characters in a textbox?
This is simple for you guys, please help..
thanks.. ^_^
Printable View
hi guys,
how could I disable letters and special characters in a textbox?
This is simple for you guys, please help..
thanks.. ^_^
Code:private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar) || e.KeyChar == '.'))
{
e.Handled = true;
}
}
i tried to use in C# but unfortunately the code youve given didnt work. But when I convert it to a vb code, it works well,
what will be the problem??
hm? really? what's the error?
there's no error, but nothing happens,
C# is different than VB.NEt when it comes to handling events. You actually have to write the code for creating the Event Handler for the events. Check if youhave this statement in your code for InitializeComponentOr else select the text box in design mode, press F4 and in the Properties window select the lightning icon in the toll bar, this will show the events, double click the KeyPress and it will automatically create the event handler for you.Code:this.textBox1.KeyPress += new System.EventHandler(this.textBox1_KeyPress);
Further to what Shuja Ali posted, if you already have the method written then you can select it from the drop-down list for the desired event in the Properties window.
ahh ok.. thanks.. now I know,,
thank you very much.,,