C# c“文本框”;介于;验证

C# c“文本框”;介于;验证,c#,winforms,validation,textbox,C#,Winforms,Validation,Textbox,我试图让一个文本框验证输入是否为1到100之间的数字 例如: if (textBox.Text is equal to numbers between 1 and 100) { do this; } else { do this; } 这是用于jpeg压缩的轨迹栏的表单验证,只能有介于1和100之间的数值。我该怎么做 首先,您需要将文本框中的输入从字符串转换为整数 string textBoxvalue = textBox.Text; int textBoxIntVa

我试图让一个文本框验证输入是否为1到100之间的数字

例如:

if (textBox.Text is equal to numbers between 1 and 100)
{
    do this; 
} 
else 
{ 
    do this; 
}
这是用于jpeg压缩的轨迹栏的表单验证,只能有介于1和100之间的数值。我该怎么做


首先,您需要将文本框中的输入从字符串转换为整数

string textBoxvalue = textBox.Text;
int textBoxIntValue = int.TryParse(textBoxvalue)
然后需要检查所需条件的值

if(textBoxIntValue > 0 && textBoxIntValue <= 100)
{
//do THIS
}
if(textBoxIntValue>0&&textBoxIntValue
String text=TextBox.text;
试一试{
long value=long.parse(text.trim());
如果(值>0&&值<101){
//在这里做点什么
}
否则{
//做点别的
}
}
捕获(例外e){
Show(“请检查您的输入并重试”);
}

您使用的技术是什么?WebForms、WinForms、WPF?我使用的是Windows窗体。我会检查您是否可以在其属性中设置轨迹栏的最小值和最大值。
String text = TextBox.Text;
try{
    long value = long.parse(text.trim());
    if(value > 0 && value < 101){
       //do something here
    }
    else{
       //Do something else
    }
}
catch(Exception e){
   Messagebox.Show("Please check you input and try again");
}