如何将 TextBox 标记为空?

How to mark TextBox as empty?

当没有在任何文本框中输入文本时,我想要打开一个新表单,其中包含一条消息

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.IsNullOrEmpty or string.IsNullOrWhiteSpace 函数来检查 TextBox 是否为空。

if(string.IsNullOrEmpty(TextBox1.Text))
{
  // do something
}