textbox只允许输入数字

private void txtUserId_KeyPress(object sender, KeyPressEventArgs e)
{
            //如果输入的不是数字键,也不是回车键、Backspace键,则取消该输入
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar!=(char)13 && e.KeyChar!=(char)8)
            {
                e.Handled = true;
            } 
} 
原文地址:https://www.cnblogs.com/armanda/p/3545997.html