點擊TextBox控制項,右手邊事件欄裡找到KeyPress,點擊兩下,輸入如下程式碼即可。
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b') { e.Handled = true; MessageBox.Show("Error!Please input the right number!"); } }
沒有留言:
張貼留言