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;
    }
}
posted on 2012-01-31 23:28  一路前行  阅读(1635)  评论(0编辑  收藏  举报