日期:2014-05-19  浏览次数:20712 次

(C#)怎么样限制文本框里只能输入数字,在线等答案
如题
在线等答案

------解决方案--------------------
在TextChange事件里引用该方法。
public static void ValidNum(System.Windows.Forms.TextBox textbox, int minValue, int maxValue)
{
if (textbox.Text== " ")
return;

if (IsNumeric(textbox.Text)==false||Convert.ToDouble(textbox.Text) <minValue||Convert.ToDouble(textbox.Text)> maxValue)
{
textbox.Text=textbox.Text.Substring(0,textbox.Text.Length-1);
if (textbox.Text.Length> =1)
{
textbox.SelectionStart=textbox.Text.Length;
}
}


}