0

Is there a way to make it so that, when I click a button, instead of needing to bring up a new dialog for my next screen, it just 'replaces' what's on the screen? (For instance, the default screen is a main menu with some buttons, which lead to more in depth screens, like Parts Inventory, and all of it's options now being on the screen).

In the realm of stacking panels, how efficient is this for a larger system? I need at least 30-40 screens going on.

Edit: I'm using Visual Studio 2010 to do this project for school, and using Windows 7 with the default packages.

user3169698
  • 143
  • 5
  • 23

2 Answers2

0

You can use multiple panels stacked and show/hide them depending on what you want to display

56ka
  • 1,463
  • 1
  • 21
  • 37
0

Instead of creating a new forms for each screen you can create a new user control for each screen. Then you could have one form with a panel and loading the control into the form instead of creating a new form showing it and hiding the old one. Youcould do something like this:

...
MyControlWasForm1 form1 = new MycontrolWasForm1(); // this is a user control
panel1.Controls.Clear();
panel1.Controls.Add(form1);
...

You could also keep references to the old control if you want to be able to go back then just reload it into the panel.Controls when needed. Keep in mind if you don't have a variable referencing the control outside of the method, then when you remove it from the controls it would get garbage collected.

...
//property on main Form
public MyControlWasForm1 Form1 { get; set; }
...
//in method
if(Form1 == null) Form1 = new MycontrolWasForm1(); // this is a user control
panel1.Controls.Clear();
panel1.Controls.Add(Form1);
...
Nick Bray
  • 1,953
  • 12
  • 18
  • I tried to do this, but it gives me an ArgumentException when I load the form into it. PartsInventory parts = new PartsInventory(); pnlMain.Controls.Clear(); pnlMain.Controls.Add(parts); The third gives me an argument exception. Should I be trying to load the form in a different way, or is there a way to load a form's controls into this new panel? – user3169698 Jan 13 '14 at 13:14