Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tabpages in a Tabcontrol

Status
Not open for further replies.

Flupke

Programmer
Jun 26, 2002
94
BE
Is it possible to hide some tabpages of a tabcontrol through code in VB.NET 2005?
The property visible or enabled (true or false) doensn't seem to exist.
How can I achieve to hide some tabpages?

Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
 
I managed this by storing all the info for what is one the page, including controls, then removing the page. Then when I wanted it back I add the page, and restore all the controls and data.

The only other way I can think of to do it is to design your own control. Which I have not yet mastered.

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
As Rebecca suggested, you could remove and add the page
depending on whether you want to have it displayed.

But i don't think that you need to store all the info regarding the controls on the tab page, because their container is the page itself, if you remove the page, then you won't see the control, if you add the page, you'll see them. I'm saying "i think" because i haven't tested it.
 
I have tested it. When a page is removed, it is destroied, as well as all the controls on it. They have to then be recreated when the pages are added back in. I created an array of pages, added controls, then can add or remove those pages to the tab control.

Here is some of the code I used to created the pages and put them in an array.

Public Sub setTabPages()
Dim intX As Int16
For intX = 0 To 19
Dim myTabPage As New TabPage
notePages(intX) = myTabPage
Next
End Sub

Public Sub setTxtBoxes()
Dim intX As Int16
For intX = 0 To 19
Dim myTextBox As New TextBox
txtBoxes(intX) = myTextBox
AddHandler txtBoxes(intX).TextChanged, AddressOf txtBoxes_TextChanged
AddHandler txtBoxes(intX).MouseMove, AddressOf txtBoxes_MouseMove
notePages(intX).Controls.Add(txtBoxes(intX))
txtBoxes(intX).Dock = DockStyle.Fill
txtBoxes(intX).Multiline = True
txtBoxes(intX).ScrollBars = ScrollBars.Vertical
noteSaved(intX) = False
noteName(intX) = "Un-named"
Next
End Sub

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
Well,
i've just tried removing the adding back a tabpage from/to a tabcontrol and it worked, all the controls were still there.

I have one form with a tabcontrol (tabcontrol1), 2 tabpages(tabpage1 and tabpage2) each page with a textbox on it.

i added two buttons to the form, here's the code behind the buttons' click event:

Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TabControl1.TabPages.Remove(TabPage2)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TabControl1.TabPages.Add(TabPage2)
    End Sub

I did it in vb2005, if it matters.
 
I have vb2003, and it does not work that way for me. I'd love to get my hands on 2005 and see what other diferences there are.

Becca

Somtimes, the easy answer is the hardest to find. :)

Still under construction ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top