如何将TextBox标记为空?[重复]

问题描述 投票:0回答:1

当在任何一个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.'"

c# .net winforms textbox
1个回答
4
投票

你可以使用 string.IsNull或Emptystring.IsNullOrWhiteSpace 函数来检查 TextBox 是空的。

if(string.IsNullOrEmpty(TextBox1.Text))
{
  // do something
}
© www.soinside.com 2019 - 2024. All rights reserved.