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?
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:
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.