Add user control to new tab control vb.net

taz8020
taz8020 used Ask the Experts™
on
Hi I have about 12 user controls, when someone clicks a button (which is in the left panel) i want to load the contol in the right panel showing the tab. If someone clicks another button it opens a new tab and put the control in that tab.

At the moment when someone clicks the button it just opens the usercontrol in the panel on the right. If they click a different button it loads the new control over the exiting one. All i want to do is as they open a new one, open it in a new tab so they can switch between tabs.

I know i could create a tabcontrol in design view and put all the controls on different tabs however some controls have a lot of data and I what to just load them as required.

Hope this makes sense.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Add a TabPage to your form and add your User Control to it....

        Dim tp As New TabPage
        With tp
            .Text = "Tab Text"
            .Controls.Add(YourUserControl)
        End With
        Me.TabControl1.TabPages.Add(tp)

Wayne

Author

Commented:
Thats great just what i need. Just a quick question how do I check if that tab already exits? and also if they click close how do I close a tab by name?
If you also set the Name property of the TabPage, you can use this to determine if a TabPage already exists....

        If Not Me.TabControl1.TabPages.ContainsKey("TabName") Then
            'add your tab page
        End If

To remove a Tab given a Name, you would use this....

        Me.TabControl1.TabPages.RemoveByKey("TabName")

Wayne
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
You Are a star, thanks.

Author

Commented:
Hi webtubbs, sorry just one lat thing how do you show a tab by name? I have tried

MainForm.TabControl1.SelectedTab = MainForm.TabControl1.Name("Customers")
To set the SelectedTab given a Tab Name of "Customers", you would use this....

    Me.TabControl1.SelectedTab = Me.TabControl1.TabPages("Customer")

Wayne

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial