473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I Add a form as a TabPage

Visual Studio 2003 Windows Forms application:

Is there a way that I can add a form as a TabPage?

My goal is to develop a series of forms and load the dialogs dynamically in
a tab control based on the user selection of a particular function. I would
like to leverage the usefulness of the Form Designer to layout my dialogs and
then load them into TabPages.

I tried setting the TabPage as the Form.Parent and various other things; all
of which would either fail to compile or throw exceptions. I was unable to
find any samples that took this type of approach. I remember in the MFC
world that this was the standard way to develop tabbed dialos.

Any Ideas?

Thanks
Nov 17 '05 #1
6 32112
I found a solution, but it seems like there should be a more elegant way to
do this. This is what I did. I created a TabControl in the form with a
single TabPage that contains all my controls. When I add a new TabPage in my
master form, I instantiate the child form and hand the master TabControl the
TabPage from my child form in the Add() method. I never call Show() on the
child form. Everything displays OK, but I haven't put any code or event
handling in yet to see what traps lie ahead with this.

My goal here is to be able to take advantage of the Form Designer to create
the tab pages that will number around 100 or more and load my TabPages at
runtime based on user input.

Thoughts?

Thanks
Nov 17 '05 #2
On Wed, 18 May 2005 19:52:05 -0700, Sleepy wrote:

Hi Sleepy
Is there a way that I can add a form as a TabPage?

My goal is to develop a series of forms and load the dialogs dynamically in
a tab control based on the user selection of a particular function. I would
like to leverage the usefulness of the Form Designer to layout my dialogs and
then load them into TabPages.

I tried setting the TabPage as the Form.Parent and various other things; all
of which would either fail to compile or throw exceptions. I was unable to
find any samples that took this type of approach. I remember in the MFC
world that this was the standard way to develop tabbed dialos.


I think the best way would be to do that with usercontrols. For each page
you create a usercontrol where you can put all the required controls to it
in the designer (same way as with forms) and then depending on the users
input you load the corresponding usercontrol in the tabpage.

--
Claudio Grazioli
http://www.grazioli.ch
http://www.grazioli.ch/HommingbergerGepardenforelle/
Nov 17 '05 #3
Thanks Claudio, that is helpful. I had not used the UserControl before this.
This is much better that my first approach.

I see that I have to change the inheritance to TabPage from UserControl in
order to add it to the TabControl. This is fine except that the Designer
then messes up the layout if I open it in the designer while it is inherited
from TabControl.

I just saw a post warning of this and it just said to be careful to change
the inheritance back to UserContriol before entering into the Designer. I
think I can live with this but was just wondering if there is a smoother way
to manage this without having to toggle the inheritance.

Thanks again!
Nov 17 '05 #4
On Thu, 19 May 2005 06:02:05 -0700, Sleepy wrote:
Thanks Claudio, that is helpful. I had not used the UserControl before this.
This is much better that my first approach.

I see that I have to change the inheritance to TabPage from UserControl in
order to add it to the TabControl. This is fine except that the Designer
then messes up the layout if I open it in the designer while it is inherited
from TabControl.

I just saw a post warning of this and it just said to be careful to change
the inheritance back to UserContriol before entering into the Designer. I
think I can live with this but was just wondering if there is a smoother way
to manage this without having to toggle the inheritance.

Thanks again!


I would recommend letting it always inherit from UserControl. And then you
add the usercontrols programmaticall y to the TabPages (with Dock=Fill).

Then you don't have to switch for and back with what to inherit from when
changing to the designer.

--
Claudio Grazioli
http://www.grazioli.ch
http://www.grazioli.ch/HommingbergerGepardenforelle/
Nov 17 '05 #5
On Thu, 19 May 2005 06:02:05 -0700, Sleepy wrote:
Thanks Claudio, that is helpful. I had not used the UserControl before this.
This is much better that my first approach.

I see that I have to change the inheritance to TabPage from UserControl in
order to add it to the TabControl. This is fine except that the Designer
then messes up the layout if I open it in the designer while it is inherited
from TabControl.

I just saw a post warning of this and it just said to be careful to change
the inheritance back to UserContriol before entering into the Designer. I
think I can live with this but was just wondering if there is a smoother way
to manage this without having to toggle the inheritance.

Thanks again!


I would recommend letting it always inherit from UserControl. And then you
add the usercontrols programmaticall y to the TabPages (with Dock=Fill).

Then you don't have to switch for and back with what to inherit from when
changing to the designer.

--
Claudio Grazioli
http://www.grazioli.ch
http://www.grazioli.ch/HommingbergerGepardenforelle/
Nov 17 '05 #6
I see, that is much better.

So now I do this:

Project/Add New/User Control
Add my controls to the new UserControl
When it is time to dynamically add my tab page to the TabControl, I do the
following:

TabPage myTabPage = new TabPage(sometex t)
myUserControl = new myUserControlTy pe()
myUserControl.D ock = DockStyle.Fill
myTabPage.Contr ols.Add(myUserC ontrol)
myTabControl.Ad d(myTabPage);

This works great, thanks again for your help!

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
13575
by: TMB333 | last post by:
I've researched as much as I can on the issue, but I've not found any clearly defined statement that acknowledges that the Hide method for a TabPage object just doesn't do what it's supposed to do. This appears to be a bug, or maybe I'm using it incorrectly? TabPage.Hide should hide the referenced TabPage object, should it not? Do I have to 'refresh' the Windows form somehow? The closest I've come to any means of hiding a TabPage from...
8
12067
by: touf | last post by:
Hi, I've a tabcontrol that contains many similar tabpages (exactly the same structure with different information), the tabpages number isn't known in the design time it depends of the data. Is there a way to clone ( copy the structure) a tabpage to create anew one by code? thanks.
4
3490
by: Supra | last post by:
I have a tab control in a which a few of the tabs include an AxWebBrowser browser control. Let say i have currently tabpage2 and i typed url in combobox when i pressed enter it doesn't display webbrowser instead i can do create new tab. ne one knows how to display currrently displayed regardless of tabpage(s)? here is code: Public Sub AddBrowserTab() AxWebBrowser1.Visible = False Dim newPage As TabPage = New TabPage(Text) ' Delcare and...
2
2210
by: GatorBait | last post by:
Hi everyone, I have a tabcontrol on a form that contains 4 tabs. I want to make each tab a seperate form because there is a great deal of code behind each page, and organizationally it was easier to have each one seperate. My idea was to just add and remove each form as necessary based on what page the user clicked on, but I am getting an error when I try to add the form as a tabpage: Dim frm as new Form1
4
1709
by: Philip Wagenaar | last post by:
I have made a form with a tab that containts groupboxes and those contain checkboxes. When I run the application sometimes the outlining for some groupboxes are not shown, if I switch tabs and back sometimes all outlining is shown and sometimes are not shown. I have no idea what is going wrong. What also is weird is that when I open the form from my main application I can resize the form, even though it is locked, and that when I cut...
8
3585
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
12
2368
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1 from the User Control in Form2 ? Hope this is clear enough...
6
4566
by: ray well | last post by:
i want a user to be able to change tab pages thru the keyboard, i tried entering the TabPage.text as '&1 Names', "&2 Addresses', etc., so that the user can change pages by type ALT 1, ALT 2, on the keyboard. but the text showing up in the tab is '&1 Names' instead of the '1' being underlined, and being able to be accessed thru the keyboard. how can i get a user to be able to change from TabPage to TabPage thru the keyboard? i find it...
0
1983
by: mustividyavtahi | last post by:
I am developing a windows application using c# in that i used tabcontrol in MDI form to display the child forms. that is working fine. but my problem is when i click a button in that tabpage (child form) it must open another form that also as tabpage which i am not getting . pls help me in this ...pls..... here is the code through which i am creating tabpages. public void settab(Form f2) { tabControl1.Visible = true;...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.