简体   繁体   中英

Hide creation/initialation of form controls

I have several forms of which the containing controls are created and/or initialized at runtime. I do this in the Load event, but still, when the form is displayed, I can still see some forms being initialized.

In my understanding the Load event is happening before the form is displayed, so this shouldn't be a problem.

What am I missing here or what can I do to prevent this?

Try calling this.SuspendLayout(); at the beginning of your Load Event and call this.ResumeLayout(); in the last line of the Load event .

Create your items inside the constructor instead of load. Just like auto-generated code InitializeComponent() that's inside the Form constructor, you can create instances of your controls and other objects after that line as needed.

Try to make form invisible in costructor and after your runtime initialization in Load event handler is completed show it. Or you can try to override OnLoad() method in your custom form and put base.OnLoad() after your custom actions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM