How to prevent UserControl loading delay in TabControl?

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

+3
source share
3 answers

TabControlIt does not process controls specifically, in fact it is normal in any case, when the event is Loadto UserControloccur immediately before the control is displayed for the first time. TabPageIt is responsible for displaying the control, so it will only be "loaded" on the first choice.

To overcome this (completely normal) behavior of Windows Forms, you can transfer your initialization code to a separate method and call it when it loads Form, or instead, you can simply put your initialization code in the constructor UserControl. In any case, you can immediately do your initialization.

+2
source

Tabcontrol SelectTab() Form Load.

+1

I was just looking for how to achieve the default behavior you are describing. I support an application that does not delay the loading of tabs. It turns out that the tabs were initialized in the load event instead of the constructor.

So, if you add tabs to tabcontrol in the form load event, all the tab controls will have their load events fired as part of the TabPages.AddRange tab

0
source

Source: https://habr.com/ru/post/1773773/


All Articles