检查文本框中的值 [英] Checking the value in a textbox
本文介绍了检查文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在WPF/Visual C#中使用文本框和按钮执行以下操作
I would like to perform the following operation using a textbox and button in WPF/ Visual C#
private button_click()
{
if ( textbox.text ! = integer) //something like that
{
MessageBox.Show("enter a valid number");
textbox.Text.clear();
<< get the input from user again using the same textbox and request the user to click the button again
}
else
{
newCar.cylinders = double.Parse(textBox.Text);
}
}
任何帮助将非常感激.谢谢.
Any help would be much appreciated. Thanks.
推荐答案
只需执行以下操作:
Just do this:
int value;
if (Int32.TryParse(textBox.Text, out value))
{
// do something
}
else
{
// show error
}
这篇关于检查文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文