tags:

views:

1580

answers:

4

I have a form that is very slow because there are many controls placed on the form.

As a result the form takes a long time to loaded.

How do I load the form first, then display it and while loading delay show another form which that have message like "Loading... please wait.?"

+5  A: 

You want to look into 'Splash' Screens.

Display another 'Splash' form and wait until the processing is done.

Here is a quick and dirty post on how to do it.

Here is a better example.

David Basarab
+4  A: 

You should great a background thread to to create and populate the form. This will allow your foreground thread to show the loading message.

unholysampler
You can't really create and use a form in Windows Forms in a non-UI thread....
Reed Copsey
+2  A: 

You can take a look at my splash screen implementation: http://stackoverflow.com/questions/510765/c-winforms-startup-splash-form-not-hiding/510786#510786

Grzenio
+1  A: 

Using a separate thread to display a simple please wait message is overkill especially if you don't have much experience with threading.

A much simpler approach is to create a "Please wait" form and display it as a mode-less window just before the slow loading form. Once the main form has finished loading, hide the please wait form.

In this way you are using just the one main UI thread to firstly display the please wait form and then load your main form.

The only limitation to this approach is that your please wait form cannot be animated (such as a animated GIF) because the thread is busy loading your main form.

PleaseWaitForm pleaseWait=new PleaseWaitForm ();

// Display form modelessly
pleaseWait.Show();

//  ALlow main UI thread to properly display please wait form.
Application.DoEvents();

// Show or load the main form.
mainForm.ShowDialog();
Ash
exist way to using animated images in your approach to still animated?
Sadegh
@Sadegh, you would need to use a control on your please wait form that internally creates a thread to animate the image. I don't think the standard PictureBox does this. However if you definitely need animation then some of David's linked pages are worth looking at.
Ash