private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( ! ( char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar) ) ) e.Handled = true; }