-2

When there is no text entered in any of TextBoxes, I want a new form to open with a message in it

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();
    }

But I get an error on the following lines

    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.'"

DimityrU
  • 11
  • 5
  • 2
    Does this answer your question? [Check Whether a TextBox is empty or not](https://stackoverflow.com/questions/34298857/check-whether-a-textbox-is-empty-or-not) The exact duplicate – Pavel Anikhouski May 26 '20 at 09:45
  • What do you mean by 'mark as empty' ?? – TaW May 26 '20 at 10:14
  • @Taw When there is no text in TextBoxes – DimityrU May 26 '20 at 10:33
  • Folks are trying to help you but you make it really hard! What do you mean by 'mark' ??? Also: 'no text' or no valid numbers'? also data missing in one or all boxes? - General rule until you can't express your goal clearly you can't write code for it.. – TaW May 26 '20 at 10:38

1 Answers1

4

You could use string.IsNullOrEmpty or string.IsNullOrWhiteSpace function to check if the TextBox is empty.

if(string.IsNullOrEmpty(TextBox1.Text))
{
  // do something
}
JeremyRock
  • 396
  • 1
  • 8