i have a form that has some six - seven text boxes. few text boxes needs to accept only numeric chars i.e from 0-9, a decimal poing and + or -
i handled the textbox key press event
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& e.KeyChar != '.')
{
e.Handled = true;
}
}
Now i have to write the same code for all the textboxes which i felt is redudant. I created a new class MyTextBox derived from TextBox and added the above code into it.
In the designer mode i drag and drop the textbox control .. go to the Designer.cs file and change the line to
private MyTextbox m_txtName = new MytextBox();
Now the problem is that if i add a new button or any control to teh form the designer.cs file is changed/updated... and the aboe line is changed to the normal TextBox and i got to go replace this everytime ... can i avoid this ?
Note: I do not want to use MasktextBox or numericKeydown control.