C#Winform限制Textbox只能输入数字

/// <summary>
/// 数字校验
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtAlarmPhone_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
    {
        e.Handled = true;
    }
}
原文地址:https://www.cnblogs.com/zhangpengshou/p/2334066.html