I've followed this guide
How do I make a textbox that only accepts numbers?
The method provided limits the characters we can input on the box
private void textBox18_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != ','))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == ',') && ((sender as TextBox).Text.IndexOf(',') > -1))
{
e.Handled = true;
}
}
it's working very well, but there's a catch, i have to add the event handler to 100+ text boxes. Is there a simpler way to do this? Since it envolves both the designer.cs and the cs.
I'm working on winform, visual c# 2010 express edition