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 control开发者_StackOverflow社区s 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;
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.
Are you calling SuspendLayout
and ResumeLayout
before and after loading all of the Controls.
Like so
UserControlName.SuspendLayout();
//Load all of the controls
UserControlName.ResumeLayout();
This will cause it to not draw anything until it has initialized all of the controls you are trying to load.
精彩评论