Load all user controls of a form on start

1.8k Views Asked by At

My Winform application has a main form with a tab control. In each tab there is a User Control. And each user control has Controls (such as DataGridViews, etc) that are loaded on the Load event of the user control.

The problem I have is that I would like to initialize all these User Controls before my main form is displayed to the user. Currently, the main form is displayed and when the user clicks on one of the tabs, that's when the User Controls start running its Load event and that leaves my main Form blank until the controls are loaded.

So I would like to hide all these loading using a Splash screen that is displayed until all controls are loaded. I have used Splash screen before and I know how to hide and show my main form. The main point is to load all user controls on my main form's Load event.

1

There are 1 best solutions below

1
On BEST ANSWER

You need to loop through each page of the tab control. Winforms only loads a tab page when it is first visited

for(int i=1; i < tabControlName.TabPages.Length; i++)
    tabControlName.SelectedIndex = i;
tabControlName.SelectedIndex = 0;

Changing the selected index will make the tab pages load.