private void txtNum1_KeyPress(object sender, KeyPressEventArgs e) { if (!(e.KeyChar <= '9' && e.KeyChar >= '0') && e.KeyChar != ' ' && e.KeyChar != '') { e.Handled = true; } }