开发者

Can I freeze my UI rendering while my form loads?

开发者 https://www.devze.com 2023-04-12 19:31 出处:网络
Is there any way I can pause all UI Update commands in Winforms? Or I have a slight feeling I\'m trying to go about this the completely wrong way, so is there another way around my problem: I basical

Is there any way I can pause all UI Update commands in Winforms?

Or I have a slight feeling I'm trying to go about this the completely wrong way, so is there another way around my problem: I basically load a saved state of a control, which loads new controls all over it. However I do some of this in the UI t开发者_如何学Gohread, and some of the data loading from another thread, which then fills the UI.

So the effect I have when it is loading is that the user can see a few of the controls appearing in one place, then moving to another place on the form, changing values, etc.

I'd like to get a loading screen instead of this and load the controls in the background. It's quite a large application and its not THAT important so redesigning my code isn't really an option.

Can I simply stop all Update() commands on a control while a method is executing?


You can use the SuspendLayout and ResumeLayout methods to wrap the setup of UI in one operation (without the update of the rendering).

Basically (assuming SomeMethod is in the form class):

private void SomeMethod()
{
    this.SuspendLayout();
    // all UI setup
    this.ResumeLayout();
}


it really depends on your form logic, in general you should not overload the Load or Show method with too much things so that the form can be shown and drawn quickly and always look responsive.

in some cases it could help to use the SuspendLayout and ResumeLayout methods, see here: Control.SuspendLayout Method

0

精彩评论

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

关注公众号