hi Jingnan,
there actually isn't a Load event for tabPage. the one people usually
listen out for is SelectedIndexChanged on the TabControl. if you have
some events on the TabPage itself, you could trigger them by doing
something like the code below. provided your code runs quickly, this
should work fine, otherwise it will delay the user and the application
will appear 'out of control' while the tab control is flicking through
all the pages.
/// select all the tabs when the form loads to trigger events
private void Form1_Load(object sender, System.EventArgs e)
{
foreach(TabPage tab in this.tabControl1.TabPages)
this.tabControl1.SelectedTab = tab;
this.tabControl1.SelectedIndex = 0;
}
// or you could try invoking the events yourself in Form_Load
private void Form1_Load(object sender, System.EventArgs e)
{
this.tabPage1_Enter(null, EventArgs.Empty);
this.tabPage2_Enter(null, EventArgs.Empty);
}
hope this helps
tim
Si Jingnan - 30 Aug 2005 04:00 GMT
Thank you, the SelectedIndex works,but I still have questions about it
Although the Tab Page has no Load event, but all the user controls have
the Load event, so when I put a user control on one of the tab page, the
Load event of user control only called when the tab page becomes
visible, I think it is strange. why not load the user control when the
parent Load(such as a form load)?
-Jingnan Si
> hi Jingnan,
> there actually isn't a Load event for tabPage. the one people usually
[quoted text clipped - 22 lines]
> hope this helps
> tim
Mick Doherty - 30 Aug 2005 05:19 GMT
The tabpage may never be selected so why load it up until it's needed? As
Tim showed earlier, you can always force it to load at Form_Load(). You
shouldn't actually see the tabs changing as the form doesn't show until
Form_Load() has finished.

Signature
Mick Doherty
http://dotnetrix.co.uk/nothing.html
> Thank you, the SelectedIndex works,but I still have questions about it
>
[quoted text clipped - 32 lines]
>> hope this helps
>> tim
Si Jingnan - 30 Aug 2005 06:00 GMT
> The tabpage may never be selected so why load it up until it's needed? As
> Tim showed earlier, you can always force it to load at Form_Load(). You
> shouldn't actually see the tabs changing as the form doesn't show until
> Form_Load() has finished.
Yes, currently I do like what Tim saying, select every tab in Form_Load
event, I just think it is a little bit strange to write code to do it.
if the tab control has a property to say "Initialize all tab pages" when
loading, that's will be cool.
Tim_Mac - 30 Aug 2005 11:27 GMT
hi Si,
you can write your own! it would be really easy to write a class
derived from the TabControl. all you would have to do is add one new
property called InitialiseAllTabPages or something like that, and then
invoke the code i gave to the top. then you can use your own
TabControl instead of the System.Windows.Forms one. i do this sort of
thing a lot, because i think the listbox and treeview controls are also
lacking some very basic functionality.
if you're interested, see this code below, which is what i have
described above. since the TabControl itself doesn't have a Load event,
i chose the Layout event which happens when the control is first laid
out. i then remove the event to prevent it from happening again in
case the form resizes.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace MyUserControls
{
/// <summary>
/// A tab control that allows all the tabs to be loaded when the
tabcontrol loads
/// </summary>
public class SmartTabControl : System.Windows.Forms.TabControl
{
private System.ComponentModel.Container components = null;
private bool autoLoadTabPages = false;
public SmartTabControl()
{
InitializeComponent();
}
[Category("Custom Options")]
[Description("Load all tab pages when the tab control loads")]
[DefaultValue(false)]
public bool AutoLoadTabPages
{
get { return this.autoLoadTabPages; }
set { this.autoLoadTabPages = value; }
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// SmartTabControl
//
this.Layout += new
System.Windows.Forms.LayoutEventHandler(this.SmartTabControl_Layout);
}
#endregion
private void SmartTabControl_Layout(object sender,
System.Windows.Forms.LayoutEventArgs e)
{
if(this.autoLoadTabPages)
{
// store the originally selected tab to set the state of the
control back to it's original state
int originallySelectedTabIndex = this.SelectedIndex;
// iterate through each TagPage in the collection and select it
foreach(TabPage tab in this.TabPages)
this.SelectedTab = tab;
// detach the Layout event because we only want it to happen once
(could happen later if the form is resized or controls changed etc.
this.Layout -= new LayoutEventHandler(SmartTabControl_Layout);
// restore the selected tabindex
this.SelectedIndex = originallySelectedTabIndex;
}
}
}
}
Si Jingnan - 30 Aug 2005 12:14 GMT
Thanks, it is very helpful
-Jingnan Si
> hi Si,
> you can write your own! it would be really easy to write a class
[quoted text clipped - 94 lines]
> }
> }
Mick Doherty - 30 Aug 2005 20:52 GMT
I would override the OnHandleCreated method instead of using the layout
event.
I think this is a good idea so I'll add it to TabControlEX :-)
http://www.dotnetrix.co.uk/controls.html

Signature
Mick Doherty
http://dotnetrix.co.uk/nothing.html
> hi Si,
> you can write your own! it would be really easy to write a class
[quoted text clipped - 94 lines]
> }
> }
Tim_Mac - 31 Aug 2005 10:55 GMT
very good, thanks for the tip. a much more sensible event.
tim