开发者

Is there any way to load all UI controls before displaying? C# winform

I have a complicate win form with lots of controls and bulky 开发者_Python百科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


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.


@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.


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.


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())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜