Reputation: 1433
I am creating a custom TabControl
public class CtlTabs : System.Windows.Forms.TabControl
{
...
}
I can insert this inherited CtlTabs
in Design Mode from the Toolbox window.
However, whenever I drag this within the form, it creates 2 TabPages
by default. Is there a way to prevent this from happening?
I tried overriding OnControlAdded()
without success.
protected override void OnControlAdded(ControlEventArgs e)
{
// base.OnControlAdded(e);
}
I also tried CtlTabs.TabPages.Clear();
on HandleCreated/ControlAdded events.
Additional Information: For this inherited TabControl
every TabPage
is created dynamically on the fly, and it sets object data in TabPage.Tag
. So these two initially created TabPages
are useless.
Of course, the workaround for now is to add/drag in the control and delete the initial tabpages manually. I just wonder if there is a way I can prevent this.
Upvotes: 2
Views: 113
Reputation: 26642
New tab pages are created by designer. Any override in runtime code (the inherited TabControl) will not help. You need specify you own designer or "downgrade" from TabControlDesigner
to ControlDesigner
.
The downgrading is pretty simple:
[Designer("System.Windows.Forms.Design.ControlDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class MyTabControl : TabControl {
}
Upvotes: 2