如何防止TabControl中的UserControl延迟加载? [英] How to prevent delay loading of a UserControl in a TabControl?

查看:112
本文介绍了如何防止TabControl中的UserControl延迟加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现,在选择父TabPage之前,不会加载TabControl中的UserControls.有没有办法防止这种延迟加载?当主窗体加载时,我需要初始化UserControls.

I have just discovered that UserControls in a TabControl will not load until the parent TabPage is selected. Is there a way to prevent this delay loading? I need to initialize the UserControls when the main form loads.

推荐答案

TabControl不会特别对待其控件,实际上,在所有情况下,UserControl上的Load事件立即发生都是正常的第一次显示该控件之前. TabPage负责显示控件,因此仅在首次选择时才会加载".

The TabControl does not treat its controls specially, in fact it is normal under all circumstances for the Load event on a UserControl to occur immediately before the control is displayed for the first time. The TabPage is responsible for showing the control, therefore it will only be 'loaded' when first selected.

要克服这种(完全正常的)Windows窗体行为,您可以将初始化代码移至单独的方法,并在Form加载时调用它,或者可以将初始化代码放入UserControl的构造函数中反而.无论哪种方式,您都可以立即执行初始化.

To overcome this (perfectly normal) Windows Forms behaviour, you could move your initialisation code to a separate method and call it when the Form loads, or you could just place your initialisation code in the UserControl's constructor instead. Either way, you can perform your initialisation immediately.

这篇关于如何防止TabControl中的UserControl延迟加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆