want to share the same instance of a user control on separate tab pages of a tabcontrol.

i have a c# user control being used on a tab page within a tab control in a vb.net winforms project

public class SplitterViewControl : System.Windows.Forms.UserControl {

Is there a way to reuse the same instance of that control on each separate tab page

If I drag the usercontrol onto each separate tab page, I get what I would expect. SplitterViewControl2 then SplitterViewControl3.

How could I access the SplitterControl1 from across the tab pages

I hope the question makes sense.

Thanks,

-Greg



Answer this question

want to share the same instance of a user control on separate tab pages of a tabcontrol.

  • Richard Kallay

    Thank you !

    I added a panel to the tabpage and then added the same splitterview1 usercontrol to each panel for each separate tab page.

    The tabpage is not a container to display the usercontrol on. But the panel is.

    Or is the tabpage just a logical member of a tabcontrol that responds to tabcontrol/tabpage kinds of events but is not meant for the same purpose as a panel. learning by doing and seeing the results......


  • DtD

    Thought for a while, I didn't come up with a simple method. Because you can't simple use tabpage1.Controls.Add to include the user control as in the code below:



    this.label2.Text = "Show Again";
    this.tabPage2.Controls.Add(this.label2);
    this.tabPage1.Controls.Add(this.label2);

     

    It seems good, but the third statement shadows the second one. The label will be shown in tabpage1.

    A workaround would be:



    private void tabpage1_enter(object sender, EventArgs e)
    {
        this.tabPage1.Controls.Add(this.label2);
    }
    private void tabpage2_enter(object sender, EventArgs e)
    {
        this.tabPage2.Controls.Add(this.label2);
    }

     

    Then the label2 ( your user control in your example) will be shown in both tabpages. It looks like so, though not really in both.

    Hope this helps.



  • lucerias

    What do you mean by "reuse the same instance of that control on each separate tab page"

    As long as the SplitterControl1 is in your namespace, you can simply access it directly without much effort.



  • want to share the same instance of a user control on separate tab pages of a tabcontrol.