KabirPatel

Hi,

I have a tab control on a Windows form. I dynamically add a user control to each of the tabs by doing the following:

myTab.TabPages["Tab1"].Controls.Add(myUserControl)

I want the load event of the user control to be invoked for each tab. However, I have noted that the load event only fires when I actaully click on the relevant tab. Is there a way to invoke the load event without actually clicking on a tab

I have tried doing the following:

myTab.TabPages["Tab1"].Select();

myTab.TabPages["Tab1"].Refresh();

myTab.TabPages["Tab1"].Focus();

but none of them work.

Cheers,

Kabir




Re: Windows Forms General User Control Load event

timvw

Code Snippet

private void Form1_Load(object sender, EventArgs e)
{
foreach (TabPage tabPage in this.tabControl1.TabPages)
{
this.tabControl1.SelectedTab = tabPage;
}

// go back to the first tab
this.tabControl1.SelectedIndex = 0;
}






Re: Windows Forms General User Control Load event

RizwanSharp

timvw's suggestion may be the only solution because control's load event is not raised untill it is made visible for the first time.

Best Regards,

Rizwan aka RizwanSharp