当在任何一个TextBoxes中没有输入文本时,我希望打开一个新的表单,里面有一条信息。
if (rectangleBox.Checked == true && (int.Parse(side_a.Text) > 0 &&
int.Parse(side_b.Text) > 0))
{
var drawRectangle = new Rectangles(70 + int.Parse(side_a.Text),
80 + int.Parse(side_b.Text),
50 + int.Parse(side_a.Text), 70 + int.Parse(side_b.Text));
Figures.Add(drawRectangle);
};
if (string.IsNullOrWhiteSpace(side_a.Text) &&
string.IsNullOrWhiteSpace(side_b.Text) &&
string.IsNullOrWhiteSpace(side_c.Text))
{
Form1 form1 = new Form1();
Form1.ShowDialog();
}
但我在以下几行得到一个错误
if (rectangleBox.Checked == true && (int.Parse(side_a.Text) > 0 &&
int.Parse(side_b.Text) > 0))
"System.FormatException: 'Input string was not in a correct format.'"
你可以使用 string.IsNull或Empty 或 string.IsNullOrWhiteSpace 函数来检查 TextBox
是空的。
if(string.IsNullOrEmpty(TextBox1.Text))
{
// do something
}