Reputation:
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?
Upvotes: 1
Views: 122
Reputation: 4107
Try calling this.SuspendLayout();
at the beginning of your Load Event and call this.ResumeLayout();
in the last line of the Load event.
Upvotes: 2
Reputation: 1479
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
Upvotes: 0
Reputation: 4893
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.
Upvotes: 1