如何防止TabControl中的UserControl延迟加载? [英] How to prevent delay loading of a UserControl in a TabControl?
问题描述
我刚刚发现,在选择父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屋!