Form as TabPage???

G

GatorBait

Hi everyone:

I have a form that has a tab control on it with 4 pages. There is a
lot of code behind each page as well as many controls on each page so I
decided to make each indidvidual page a seperate form, for organization
purposes. I am getting an error when I try to add the form to the tab
control. The error message tells me that the form cannot be converted
to type tabpage. Here is the code I am using:

Dim frm as new Form1
tabMain.TabPages.Add(frm)

Does anyone have any ideas?

I should also mention that I am still pretty new to VB.NET so I wanted
to ask if I am doing this the proper way. Is there a different
methodology that I should be following?

Thank you in advance for your insight!
 
H

Herfried K. Wagner [MVP]

GatorBait said:
I have a form that has a tab control on it with 4 pages. There is a
lot of code behind each page as well as many controls on each page so I
decided to make each indidvidual page a seperate form, for organization
purposes. I am getting an error when I try to add the form to the tab
control. The error message tells me that the form cannot be converted
to type tabpage.

I suggest to use usercontrols instead of forms which should be embedded into
the tabcontrol. Choose "Project" -> "Add user control..." to add a
usercontrol to your project.
 
C

Chris Dunaway

GatorBait said:
Dim frm as new Form1
tabMain.TabPages.Add(frm)

Change your code to this:

Dim frm As new Form1
frm.TopLevel = False
frm.Parent = tabMain.TabPages(0)

frm.Show()


The form should now be visible inside the tab page. You might want to
set the form's FormBorderStyle property to none.
 
C

Chris Dunaway

Herfried said:
I suggest to use usercontrols instead of forms which should be embedded into
the tabcontrol. Choose "Project" -> "Add user control..." to add a
usercontrol to your project.

Herfried, do you know if there is any technical reason not to use a
form? Both the Form class and UserControl class have the same
inheritance chain. And, of course, Form has other properties that
UserControl might not have.

I am just curious.
 
H

Herfried K. Wagner [MVP]

Chris,

Chris Dunaway said:
Herfried, do you know if there is any technical reason not to use a
form? Both the Form class and UserControl class have the same
inheritance chain. And, of course, Form has other properties that
UserControl might not have.

Forms are not designed for being embedded into other controls or forms,
except in MDI scenarios.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top