views:

301

answers:

4

I have a complicate win form with lots of controls and bulky repaints, controls resizeing and positioning according to user screen, this causes the form to be shown while doing some rendering and repainting.

Is there any way to load UI and prepare it before displaying??I mean showing final UI after the whole repainting events done.

If using splash screen, before loading the main form, how should I do that??

Thanks

+2  A: 

Perhaps using SuspendLayout() and ResumeLayout() would work.

From MSDN:

The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. For example, you would typically call the SuspendLayout method, then set the Size, Location, Anchor, or Dock properties of the control, and then call the ResumeLayout method to enable the changes to take effect.

Andy West
+1  A: 

You could create a "Loading" panel and cover your entire form with it temporarily while things load. You could maybe try calling PerformLayout on your layout managers prior to calling Form.Show to get them to front load the layout task.

A splash screen is easy enough. You can just show a topmost form and close it when your main form is done being shown, perhaps in the Activated event.

Kevin Stafford
Thanx for replys. SuspendLayout and ResumeLayout methods didnt work, because most of ui is created by visual studio wizard and these methods are used automatically there, in the code behind of the forms.I didnt get the idea how to add [ "Loading" panel ] for covering the form and but i tried PerformLayout and it didn't work.I have lots of custom user controls in the form, and I found double buffer. I set doublebuffer property of the user controls to True. and it works a little better now.
Nabil
A: 

in your main:

    MyMainForm hostInterface;

    static void Main( )
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        hostInterface = new HostInterface();
        // do some stuff to get the form ready
        // here you can optionally instance a splash screen
        MySplashScreen splash;
        hostInterface.Load += splash.Close();    // <- might not be 100% accurate
        splash = new MySplashScreen();


        Application.Run(hostInterface);
    }

See how that works for you. The difference is that you are instantiating the form prior to running anything. I threw in an option for instancing a splash screen.

Compare the above to the standard auto-generated code:

static void Main( )
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new MyMainForm());
        }

Even without adding a splash screen, I have found that declaring the MyMainForm myform = new MyMainForm() has been better at loading all the controls prior to Application.Run(new MyMainForm())

dboarman
A: 

@Kevin has the right idea and it's the approach I would use:

  1. Drop a Panel on your form and set Dock to Fill so that it covers the entire form.
  2. Drop a ProgressBar into the center of the panel with the Style property set to Marquee. This will make it scroll constantly.
  3. Now, at the end of your form's constructor (or Load event handler, if you are using it), call the SendToBack() method of your panel to expose the fully rendered controls.
Ken
perfect tanx to all.
Nabil
how about an accepted answer and some up votes?
Ken