受限字符的按键异常

Keypress exceptions on restricted characters

如何允许 space 栏在仅限数字的文本框中使用?

 private void CLimitTxt_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!char.IsNumber(e.KeyChar))
        {
            MessageBox.Show("You can only enter numbers within this textbox", "Error");
            CLimitTxt.Text = "";
            e.Handled = true;
        }
    }

我是否需要声明一个带有异常的 var 正则表达式?

就这么简单:

private void CLimitTxt_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsNumber(e.KeyChar) && !e.KeyChar == ' ')
    {
        MessageBox.Show("You can only enter numbers within this textbox", "Error");
        CLimitTxt.Text = "";
        e.Handled = true;
    }
}