我使用下面的代碼來禁止任何字符,除了在文本框中的數字......但它允許'。'字符!我不希望它允許點。無法確定'。' keybox爲文本框KeyPress事件
private void txtJustNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit((char)(e.KeyChar)) &&
e.KeyChar != ((char)(Keys.Enter)) &&
e.KeyChar != (char)(Keys.Delete) &&
e.KeyChar != (char)(Keys.Back)&&
e.KeyChar !=(char)(Keys.OemPeriod))
{
e.Handled = true;
}
}
看看[此線索](http://stackoverflow.com/questions/463299/how-do-i- make-a-textbox-that-only-accepts-numbers) – Default