Resolved If form exists

PDS8475

Active member
Joined
Jun 25, 2019
Messages
41
Programming Experience
Beginner
Hi I have two forms
Welcome_form
Repairs_form

The Repairs_form has a cancel button

in the click event of the cancel button I have wrote

C#:
            N = TempName_label.Text;
            Welcome_form wel = new Welcome_form(N);
            wel.Show();
            this.Close();

Also on the form closing event of the Repairs_form I have put

C#:
                N = TempName_label.Text;
                Welcome_form wel = new Welcome_form(N);
                wel.Show();

I need code to open the Welcome_form
when the Repairs_form is closed

However because of this clicking the cancel button causes two instances of the Welcome_form to open
How do I go about creating an If statement on the form closing event to check if the Welcome_form is already open

I take it would be something like

C#:
                if (Welcome_form.Exists = false ) {
                N = TempName_label.Text;
                Welcome wel = new Welcome(N);
                wel.Show();
            }

Thanks in advance
 
Last edited:
Why use an if statement to prevent the second form being created when you could just not create the first one?
Duh you're right. I wasn't thinking that all I needed on the cancel button was the code to close the form, which then runs the code to open the other form since it's closing
 
Back
Top Bottom