Garth Edmunds

Garth Edmunds

  • NA
  • 22
  • 10k

Controlling Multiple Forms in C#

Sep 8 2018 12:39 PM

This is my first question so I hope I am doing this right. I am currently using Visual Studio Express 2017 doing a C# Windows Forms App project.

I have searched through Stack Overflow and YouTube for a similar examples but could find none. In the image attached, I have 3 forms in the project. Form1 which is the main controlling form and has 2 buttons on it. Form2button for Form2 and Form3button for Form3. When I click From2button, I can keep clicking and open multiple Form2's as well open multiple Form3's without limitations. I would like to run the program that if I click on Form2button it can only load one instance of Form2 and the same with Form3button.

However if I click Form3button and Form2 is open, I want Form2 to close and only have Form3 open as well as is Form3 is open and I click on Form2button, Form3 will close and Form2 will open. All the time Form1 is active on the screen.
 
namespace MultiWindows 

{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void Form2button_Click(object sender, EventArgs e)     
{         
Form2 f2 = new Form2();         
f2.Show();     
}      
private void Form3Button_Click(object sender, EventArgs e)     
{         
Form3 f3 = new Form3();         
f3.Show();     
} 
} 

}


Answers (4)