I would use UserControls rather than Forms.
One way to do exactly what you want is to create a UserControl for each
TabPage.
Set the Tag property of each tabpage to the name of the UserControl you
created specifically for it.
Then simply add the following code to your form (assumes your tabcontrol is
named TabControl1):
\\\
Private Sub MainForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
For Each tp As TabPage In Me.TabControl1.TabPages
If Not (tp.Tag Is Nothing) Then
Dim ctrl As Control = CreateTabChild(tp.Tag.ToString)
If Not (ctrl Is Nothing) Then
ctrl.Dock = DockStyle.Fill
tp.Controls.Add(ctrl)
End If
End If
Next
End Sub
Private Function CreateTabChild(ByVal ctrlName As String) As Control
Dim assyName As String = Me.GetType.Assembly.GetName.Name
Dim assy As Reflection.[Assembly] = _
Reflection.[Assembly].LoadWithPartialName(assyName)
Return CType(assy.CreateInstance(assyName + "." + ctrlName), Control)
End Function
///
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
<p1*******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ok, I think I've got it working, so far so good. But...I don't know if
it's the right way or would it cause problems down the track. Following
is what I'm doing:
1. create a number of forms, one of them is the main form and contains
the tab control
2. add some tab pages to the tab control in the main form
3. add other controls into the rest of the forms (the forms are
essentially the tab pages)
4. change "Inherits System.Windows.Forms.Form" to "Inherits
System.Windows.Forms.TabPage" in the forms
5. comment out "Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)"
in the forms
6. in the main form, change "Me.TabPage1 =
System.Windows.Forms.TabPage" to "Me.TabPage1 = New Form2", tabpage2 =
form3, tabpage3 = form4, and so on...
Change the forms to System.Windows.Forms.TabPage loses the design view,
so I have to change it back to System.Windows.Forms.Form and uncomment
Me.AutoScaleBaseSize when I need to edit the layout at design time.
What do you think? Is this correct or awfully wrong?