How can I add TabPages dinamically?

DevilAkuma

Active member
Joined
Oct 24, 2005
Messages
37
Programming Experience
Beginner
Hello!

Well, I'm working in a application where the user can open several files. I have to show its content in different panels. The way to move through the panels is with the TabPage.

I've created a TabControl previously, but I don't know how can I add a TabPage to him :( I don't know how many files will be opened by the user...

Sorry about my English :p

Thanks a lot!
 
This should work for you. It's VS 2003 EA, if you're using 2005 beta; I don't know if it'll work. I don't have any experience with it yet.
VB.NET:
Private Sub odiaOpenFile_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles odiaOpenFile.FileOk
Me.txtFilePath.Text = Me.odiaOpenFile.FileName
'creat the instance of the tabpage
Dim newTab As New System.Windows.Forms.TabPage(tcTabControl.TabCount + 1)
'I'm not sure what you're wanting to place in the tabs themselves; but i'll
'just have the example add a new label with the tab number in it
Dim IndexLabel As New System.Windows.Forms.Label
IndexLabel.Text = "Tab: " & tcTabControl.TabCount + 1
newTab.Controls.Add(IndexLabel)
Me.tcTabControl.TabPages.Add(newTab)
End Sub

Edit: I am an advocate for exception handling and garbage collecting; it just seemed like too much for a quick example. :)
 
Back
Top