How to improve the loading time of winform?

Viewed 13506

I have a WinForms application. the main form is has a lot of controls and that is one of the reasons that makes it load very slow. what I would like to do is to make the form load faster.

I have set the beginupdate and endupdate. The form is not being rendered in the background worker thread, because this is the main form. There are no initial forms. When the user clicks the application icon, this is the first form that loads up. Adding a progress bar or any splash form is not a good idea for me.

I have checked other questions here on Stack overflow but they do not seem to face the same problem as I do.

If there are some examples/ideas you have in mind, it would be nice of you if you can share it with me.

5 Answers
  • If you have several controls to a parent control, call the SuspendLayout method before initializing the controls to be added.
  • After adding the controls to the parent control, call the ResumeLayout method. This will increase the performance of applications with many controls.

For example:

private void LoadData()
{
   // Suspend the form layout and load the data
   this.SuspendLayout();
   LoadMyData();   // logic to load your data will be here
   this.ResumeLayout();
}

EXPLANATION:

  1. SuspendLayout() - Stops the layout object from being updated and thus the component does not spend any time making calculations for repainting until the layout is resumed.
  2. ResumeLayout() - Recomputes the layout once after all of your changes are made, resulting improvement in performance.

Why use SuspendLayout() and ResumeLayout()

  1. It prevents layout accidents when controls have layout properties that affect each other.
  2. It adjusts multiple layout-related properties like Dock, Auto-Size etc.
Related