Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Form Tabpage loads slowly

I have a tab-control that has 4 tab pages. Each tab page contains a user-control that I add programmatically when the program first loads. For some reason the second tab-page loads slow when I click on it but the other tabs load fine. This tab-page does contain about 20 controls(text boxes, drop-downs, list boxes, etc) but no images or anything like that. Also that page has around the same number of controls as the others. Is there any way to speed up the switching of the tabs? Can I preload the tab-page at startup?

Note: It is only slow on the initial switch.

This is how I add the 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;
like image 627
Gage Avatar asked Nov 06 '22 06:11

Gage


1 Answers

This is a feature of the TabControl: The contents of a tab are only loaded when they are clicked for the first time.

It would therefore appear to be a problem of that UC on the 2nd Tabpage, look for the resources (queries) it uses.

like image 126
Henk Holterman Avatar answered Nov 10 '22 20:11

Henk Holterman