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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
TabControldoes not treat its controls specially, in fact it is normal under all circumstances for theLoadevent on aUserControlto occur immediately before the control is displayed for the first time. TheTabPageis responsible for showing the control, therefore it will only be ‘loaded’ when first selected.To overcome this (perfectly normal) Windows Forms behaviour, you could move your initialisation code to a separate method and call it when the
Formloads, or you could just place your initialisation code in theUserControl‘s constructor instead. Either way, you can perform your initialisation immediately.