C# keyPress
KeyPressでキーボードから数字およびバックスペースのみ受け付ける
入力がなかったことにする
¥bはバックスペース
|
1 2 3 4 5 6 7 8 9 10 11 12 |
private void InBox_KeyPress(object sender, KeyPressEventArgs e) { //数字およびバックスペースのみ受け付ける if ((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b')) { e.Handled = true; } if (e.KeyChar == (char)Keys.Enter) { Console.WriteLine(InBox.Text); } } |

