473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tab control with many pages

I'm working on a single form app, the form contains a tab control with
multiple pages. As a result the code gets very long in the code page,
which can be a pain to maintain, basically it's a mess.

What I'm planning to do is to break down the codes into separate
modules, i.e. one module per tab page, and pass the controls to the
module's subroutines as parameters. It should work but I think it's
wrong, or at least not the .net way of doing things.

Perhaps I should make each tab page as a class, then attach them to the
tab control. But I have little idea how to do that. Do I create user
controls then drop them into the tab pages, or should I derive my own
class from System.Windows.Forms.TabPage?

Please help, simple code snippets would be appreciated. TIA.

Nov 25 '05 #1
5 2191
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?

Nov 25 '05 #2
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?

Nov 25 '05 #3
In fact I'm thinking far too hard ;-)

Just drop the usercontrol onto the tabpage at designtime and set it's dock
property to Fill.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:u3**************@tk2msftngp13.phx.gbl...
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?


Nov 25 '05 #4
Thanks, I'm taking your suggestion.

I noticed if I change System.Windows.Forms.UserControl to
System.Windows.Forms.TabPage then the TabControl can reference it
directly, but I will lose the design view. Oh well, I guess I'd stick
to the UserControl. Cheers.

Nov 26 '05 #5
dgk
On 24 Nov 2005 23:36:19 -0800, p1*******@yahoo.com wrote:
I'm working on a single form app, the form contains a tab control with
multiple pages. As a result the code gets very long in the code page,
which can be a pain to maintain, basically it's a mess.

What I'm planning to do is to break down the codes into separate
modules, i.e. one module per tab page, and pass the controls to the
module's subroutines as parameters. It should work but I think it's
wrong, or at least not the .net way of doing things.

Perhaps I should make each tab page as a class, then attach them to the
tab control. But I have little idea how to do that. Do I create user
controls then drop them into the tab pages, or should I derive my own
class from System.Windows.Forms.TabPage?

Please help, simple code snippets would be appreciated. TIA.

Just a guess here but wouldn't partial classes be a way to go? By
default all the code would go into the form's main code module but
couldn't you move it to another module so long as it has the same
class name? VS2005 of course.
Nov 29 '05 #6

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

Similar topics

1
by: Julie | last post by:
I am trying to set some checks on my tab pages. I have many sets of tab control pages with many controls on each page. I have got the code on the button to check each control to make sure it has an...
9
by: Viken Karaguesian | last post by:
Hello all, I just discovered this NG, so you'll probably be getting some questions that have been brewing inside me for a while :>) I'm just an amateur who enjoys making websites. I use...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
4
by: Just D. | last post by:
Does anybody know an official way to setup one control on many pages, for example menu? Since we're not having a visual inheritance yet it's not very easy. One of the possible ways as I see is to...
4
by: Grant Merwitz | last post by:
Hi Is there a way to add a control to my page through the Global.asax I would like to place this code in the Session_Start page so its only added to the first page the user visits. TIA
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
7
by: ApexData | last post by:
I am using the following code in my TabControl to manage subform loads. The code assigns the subForms SourceObject. - Do I also need code to DeAssign the SourceObject when leaving the Tab, I'm...
1
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.