Windows 窗体选项卡加载缓慢
我有一个有 4 个选项卡页的选项卡控件。每个选项卡页都包含一个用户控件,我在程序首次加载时以编程方式添加该控件。由于某种原因,当我单击第二个选项卡页面时,它加载缓慢,但其他选项卡加载正常。该标签页包含大约 20 个控件(文本框、下拉列表、列表框等),但没有图像或类似内容。此外,该页面的控件数量与其他页面大致相同。有什么办法可以加快标签的切换速度吗?我可以在启动时预加载标签页吗?
注意:仅在初始切换时速度较慢。
这就是我添加用户控件的方式
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 TabControl 的一个功能:选项卡的内容仅在第一次单击时加载。
因此,这似乎是第二个选项卡上的 UC 的问题,请查找它使用的资源(查询)。
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.
您是否在加载所有控件之前和之后调用
SuspendLayout
和ResumeLayout
?像这样
这将导致它在初始化您尝试加载的所有控件之前不会绘制任何内容。
Are you calling
SuspendLayout
andResumeLayout
before and after loading all of the Controls.Like so
This will cause it to not draw anything until it has initialized all of the controls you are trying to load.