public static void TextBoxDecimalFilter(object sender, KeyPressEventArgs e) { if (e.KeyChar.ToString() == "\b" || e.KeyChar.ToString() == "." || e.KeyChar.ToString() == "-") { string str; if (e.KeyChar.ToString() == "\b") { e.Handled = false; return; } else { str = ((TextBox)sender).Text.Trim() + e.KeyChar.ToString(); } if (Utility.IsDecimal(str) || str == "-") { e.Handled = false; return; } } if (!char.IsDigit(e.KeyChar)) { e.Handled = true; } }
public static void DataGridViewIntFilter(object sender, KeyPressEventArgs e) { if (e.KeyChar.ToString() == "\b" || e.KeyChar.ToString() == "-") { string str; if (e.KeyChar.ToString() == "\b") { e.Handled = false; return; } else { str = ((DataGridViewTextBoxEditingControl)sender).Text + e.KeyChar.ToString(); } if (Utility.IsDecimal(str) || str == "-") { e.Handled = false; return; } } if (!char.IsDigit(e.KeyChar)) { e.Handled = true; } }