Question

I am dynamically assigning a form (think of it as a "pseudo tab page") to a tabcontrol.

I was doing it this way:

// Main form, which has the TabControl at design-time:

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    int TabControlWidth = tabPageBasicInfo.Size.Width;
    int TabControlHeight = tabPageBasicInfo.Size.Height;

    if (e.Node.Name == "NodeWhatever")
    {
        BasicInfoPseudoTab bipt = new BasicInfoPseudoTab(TabControlWidth, TabControlHeight);
        tabPageBasicInfo.Controls.Add(bipt);
        bipt.Show();
    }
    // else NodeThis, NodeThat
}

// Constructor on the form that is the "pseudo tab page":

// overloaded constructor, passing in the dimensions of the tab page
public BasicInfoPseudoTab(int ATabPageWidth, int ATabPageHeight) 
{
    this.TopLevel = false;
    this.FormBorderStyle = FormBorderStyle.None;
    this.Width = ATabPageWidth;
    this.Height = ATabPageHeight;
    this.Visible = true;
}

...but then I experimented with setting the Dock property:

public BasicInfoPseudoTab(int ATabPageWidth, int ATabPageHeight) 
{
    this.TopLevel = false;
    this.FormBorderStyle = FormBorderStyle.None;
    //this.Width = ATabPageWidth;
    //this.Height = ATabPageHeight;
    this.Visible = true;
    this.Dock = DockStyle.Fill;         
}

...and it works great, so I thought I'd just use the "in the box" constructor by stripping out the two args. However, that's not allowed, as get, "Type 'UserControlsOnTabPagePOCApp.BasicInfoPseudoTab' already defines a member called 'BasicInfoPseudoTab' with the same parameter types"

The Load() event is too late (when I was setting the TopLevel property there, it gave me an err msg until I moved it to the constructor).

What do I need to do to override (rather than overload) the constructor, or what other event should I use (does anything come before the Load() event?)

ALSO (I didn't want to put the same code in two different questions): the form itself displays fine on the TabControl, but the controls I've added to the form/pseudo Tag page at design-time do not display at run-time - why?

Was it helpful?

Solution

It's not a matter of overriding a constructor (constructors aren't polymorphic like that anyway) - it's a matter of the constructor already existing. I'd expect it to be present already in your code - something like this:

public BasicInfoPseudoTab()
{
    InitializeComponent();
}

You can edit that constructor, rather than declaring another parameterless one. Note that your other constructor should either chain to that one or call InitializeComponent() itself, so that all the designer code can do its stuff.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top