private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
bool isNumber = char.IsNumber(e.KeyChar);
bool isPeriod = (e.KeyChar.Equals('.'));
bool isControl = (char.IsControl(e.KeyChar)); e.Handled = (!isNumber && !isControl && !isPeriod);
}
The problem is that I have to type this in each texbox. Now there is only 3 lines of code, but if there was lot more i think this is not the best way. So the question is, how i can make some method and call it and also if there is a way to make each textbox in form numeric only.

New Topic/Question
Reply



MultiQuote




|