Windows Form tab screen loading slowly

I have a tab control that has 4 tabs. Each tab contains a user control that I add programmatically when the program loads first. For some reason, the second tab-page loads slowly when I click on it, but the other tabs load normally. This tab contains about 20 controls (text fields, drop-down lists, lists, etc.), but there are no images or anything like that. This page also has the same number of controls as the rest. Is there a way to speed up tab switching? Can I preload a tab at startup?

Note: on the start switch, it is slow.

This is how I add Usercontrol

tabPage2.Controls.Add(userControl_1); // // userControl_1 // userControl_1.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right; userControl_1.Location = new System.Drawing.Point(0, 0); userControl_1.Name = "userControl_1"; userControl_1.Size = new System.Drawing.Size(878, 646); userControl_1.TabIndex = 0; 
+4
source share
2 answers

This is the function of TabControl: the contents of the tab are loaded only the first time you click.

So this will be the problem of this UC in the second tab, find the resources (queries) that it uses.

+1
source

You call SuspendLayout and ResumeLayout before and after loading all controls.

In this way

 UserControlName.SuspendLayout(); //Load all of the controls UserControlName.ResumeLayout(); 

This will cause him to draw nothing until he initializes all the controls you are trying to load.

+1
source

All Articles