日期:2014-05-18 浏览次数:21031 次
private void textBox4_KeyDown(object sender, KeyEventArgs e) { nonNumberEntered = false; if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9 ) { if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9 ) { if (e.KeyCode != Keys.Back) { nonNumberEntered = true; } } } } private void textBox4_KeyPress(object sender, KeyPressEventArgs e) { if (nonNumberEntered == true) { e.Handled = true; } }
private void textBox1_Validating(object sender, CancelEventArgs e) { const string pattern = @"^\d+\.?\d+$"; string content = ((TextBox)sender).Text; if (!(Regex.IsMatch(content, pattern))) { MessageBox.Show( "只能输入数字!"); e.Cancel = true; } else xxxxxxx }