views:

32

answers:

1

I am making a c# windows app that has one MainForm and many User Controls (LoginPage, HomePage, MyListPage, etc.) embedded inside it. I am using Visual Studio 2005 to design the GUI.

In MainForm's constructor I do:

Controls.Add(new LoginPage());
Controls.Add(new HomePage());
Controls.Add(new MyListPage());
...
LoginPage.show();

But I have over 30 pages that I add to MainForm's constructor and I think this is the culprit of my app's lag at its runtime. Does anybody know a more standardized way of using User Controls for a one-form navigation app?

+1  A: 

I'm assuming you have a way of navigating between pages - your user controls aren't all shown at once?

If that's the case, you should be able to do the following:

  1. Create one of the user controls on construction to use as the initial page.
  2. When the user performs an action which means your app should move to another page, remove the current user control from the form, dispose of it, create a new one of the required type, and add it to the form.

If you only want to create each user control once, you can use a caching mechanism so that each one is only created once (and don't dispose of the controls as you remove them).

If you use this approach, it should get rid of some of the initial lag, and trade it for multiple smaller lags as the user navigates to each user control for the first time.

Alex Humphrey