views:

201

answers:

4

What is the fast and effective way to open Form2 from Form1?

I work in WinCE (limited memory and CPU power) so this becomes important.

+1  A: 

The easy way:

OtherFormClass NewForm = new OtherFormClass();
NewForm.Show();

If you can handle the memory, you can create the form in the background and popup when desired. This should give the user a nice, quick experience.

There may be other optimizations to alleviate memory pressure.

Michael Haren
Mitch - good idea
Michael Haren
A: 

If you want the form be open quicker in terms of user responsiveness AND you can handle the memory overhead you might consider "preloading" the form. Instantiate the form in the start up procedure of your app and cache the form in a global variable (or make it a singleton and create an instance). This increases app start up time but gives you improved responsiveness when you later show the form. If the form has a lot of controls calling show then hide against the form in start up will also preload the forms controls, further reducing the time it takes to subsequently display the form.

This is not usualy recommended on the full .net framework!

Christopher Edwards
+2  A: 

Depending on your requirements, you might trick your users to see a splash screen when your application loads. During this time, you instantiate important forms in the background. This approach should give you a few extra seconds that most users don't think of as "being slow". Users usually accept that an app starts slower if it works reasonably fast afterwards.

Sergiu Damian
A: 

Try caching forms. The killer part is the creation of the form (the creation of the windows handles e.g. the running of InitializeComponent). If you create the forms when your app starts then you will notice a small (yet noticable) gain in performance when showing the forms later. This is obviously at the cost of start up time.

So at startup:

Form1 form = new Form1();
FormStore.Add(form);

And later:

Form1 form = FormState.GetForm<Form1>();
form.Show();

That kind of thing.

Quibblesome