473,480 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

tabpage clone

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.
Nov 20 '05 #1
8 12038
Hi Touf,

|| Is there a way to clone (copy the structure) a tabpage to
|| create a new one by code?

Can you tell me what controls you have on your TabPages? Also, what,
specifically, do you want to do with the new TabPage?

Regards,
Fergus
Nov 20 '05 #2
thanks Fergus
I like to display statistic for cutomers
for each customer I create a new TabPage that contain :
- a label and a textBox that contains the customer name
- a listBox that contain the total of the sales by year.

I've created the first TabPage in the design view, and I like to create the
others by code.
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
Hi Touf,

|| Is there a way to clone (copy the structure) a tabpage to
|| create a new one by code?

Can you tell me what controls you have on your TabPages? Also, what,
specifically, do you want to do with the new TabPage?

Regards,
Fergus

Nov 20 '05 #3
"touf" <to******@hotmail.com> schrieb
thanks Fergus
I like to display statistic for cutomers
for each customer I create a new TabPage that contain :
- a label and a textBox that contains the customer name
- a listBox that contain the total of the sales by year.

I've created the first TabPage in the design view, and I like to
create the others by code.


I'd create them all by code. I'd probably derive my own class from Tabpage
and create a new instance per customer. To save some work, you could move
the code, generated by the designer for your already existing tabpage, to
you derived TabPage.
--
Armin

Nov 20 '05 #4
Hi Touf,

There is nothing in .NET to clone a Control and its children so it all has
to be done 'manually'. It <is> possible to do it with Reflection and recursion
but I think that would be overkill in this case.Thankfully, it sounds as if
your TabPages aren't too complicated.

What I recommend is that you look in the Windows Form Designer code
section and simply copy out the parts that created your first TabPage. Stick
these into a separate routine and add the appropriate parameters for things
like label captions, etc..

The event handling has to be added explicitly using AddHandler. With a
Designer-added Control, event handling is done for you, so you get:
Sub Button1_Click (sender, e) Handles Button1.Click.
You'll need to do
AddHandler ButtonX.Click, AddressOf Button1_Click
This will make Button1 and ButtonX go to the same routine for their
Clicks, so you may need to determine which one is being pressed - this will be
the sender argument.

Have a look at the example below which creates a new TabPage with a Label,
a TextBox and a Button. Note how these controls are added to the TabPage and
then the TabPage is added to the TabControl.

SuspendLayout() and ResumeLayout() are in comments. They prevent
flickering by stopping the TabControl from drawing itself unti the new
Tabpages have been added. You may not need to call these but if you do, that's
where they go.

Come back if you need further help with this. :-)

Regards,
Fergus

<code>
Private Sub AddTabPage (... <Text values, etc> ...)
Dim LabelX As New Label
Dim TextBoxX As New TextBox
Dim ButtonX As New Button

'A new Label
LabelX.Location = New System.Drawing.Point(39, 56)
LabelX.Name = "LabelX"
LabelX.TabIndex = 4
LabelX.Text = "LabelX"

'And a new TextBox
TextBoxX.Location = New System.Drawing.Point(31, 20)
TextBoxX.Name = "TextBoxX"
TextBoxX.TabIndex = 3
TextBoxX.Text = "TextBoxX"

'And a new Button
ButtonX.Location = New System.Drawing.Point(159, 28)
ButtonX.Name = "ButtonX"
ButtonX.TabIndex = 5
ButtonX.Text = "ButtonX"
AddHandler ButtonX.Click, AddressOf Button1_Click

'And a new TabPage to put them on.
Dim TabPageX As New TabPage
TabPageX.Location = New System.Drawing.Point(4, 22)
TabPageX.Name = "TabPageX"
TabPageX.Size = New System.Drawing.Size(264, 98)
TabPageX.TabIndex = 0
TabPageX.Text = "TabPageX"

'Add the controls to the TabPage.
TabPageX.Controls.AddRange _
(Control() {LabelX, TextBoxX, ButtonX})

'Add the TabPage to the TabControl.
'Me.TabControl1.SuspendLayout()
Me.TabControl1.Controls.Add (TabPageX)
'Me.TabControl1.ResumeLayout(False)

'Bring the new TabPage to the front.
TabControl1.SelectedTab = TabPageX
End Sub
</code>
Nov 20 '05 #5
"touf" <to******@hotmail.com> wrote in message news:<um**************@TK2MSFTNGP10.phx.gbl>...
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.


One option is to create a custom control (class), i.e. your tabpage
with the needed controls on it.

Good luck

Freek Versteijn
Nov 20 '05 #6
Hi Touf, Freek,

And a damn fine suggestion , too! For if you have a UserControl and change
the layout or what-have-you, it will work for all of the TabPages. Whereas, if
you go the make-a-copy route that I showed you earlier, you will have more
work to do every time your design changes. It depends on which is easier and
how stable your UI design is.

Regards,
Fergus
Nov 20 '05 #7
Thans friends,
I think that the best way I have, is to move the code of the designer to a
sub and call it with parameters...
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:uq*************@TK2MSFTNGP11.phx.gbl...
Hi Touf, Freek,

And a damn fine suggestion , too! For if you have a UserControl and change the layout or what-have-you, it will work for all of the TabPages. Whereas, if you go the make-a-copy route that I showed you earlier, you will have more
work to do every time your design changes. It depends on which is easier and how stable your UI design is.

Regards,
Fergus

Nov 20 '05 #8
yanike
1 New Member
Hi Touf, Freek,

And a damn fine suggestion , too! For if you have a UserControl and change
the layout or what-have-you, it will work for all of the TabPages. Whereas, if
you go the make-a-copy route that I showed you earlier, you will have more
work to do every time your design changes. It depends on which is easier and
how stable your UI design is.

Regards,
Fergus
THANK YOU THANK YOU THANK YOU!!!!

This is exactly what I was looking for :)
Jul 1 '06 #9

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

Similar topics

4
13548
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....
9
883
by: Robb Gilmore | last post by:
Hello, This is probably an easy one, but I have not been able to figure it out so far. I have a tab control on a windows forms app. Depending on some business logic, I need to hide/show some...
2
1673
by: JG | last post by:
Hi, I have a windows form with a TabControl on it. It has 3 tabpages on it. I have also coded a button that is supposed to 'add' a new tabpage. The code in that clicked event looks like this:...
1
7631
by: RA | last post by:
Hi 1) I want to create a TabPage class in design mode - how do I do it? What type of project should I use? Is it going to be a custom control? 2) I have a TabControl that I would like to add to...
3
3464
by: Cynthia | last post by:
I knew that "Hide" doesn't work with Tabpage if I want to hide it. I should use Remove/Add. But I have some other controls in the tabpage which I don't want to use code to dynamiclly create them....
4
10139
by: Ratan | last post by:
I have a form that has a tabcontrol with 5 tabpages. i want to rename the tabpages in runtime. Actually i want to right click the tabpage i want to rename and edit the text there itself. How to...
0
2999
by: Marc Solé | last post by:
Hi to everybody, I would like o clone a tabPage into the same tabControl with all the controls of the first tabPage. I have tried doing like this, but that way doesn't clone the controls. That...
6
4552
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...
6
12856
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello gurus, I want to have a Form with a TabControl, this TabControl will contain TabPage that has controls in it, this TabPage is prepared at design time. I want in runtime to duplicate the...
0
7046
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
6908
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
7088
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...
1
6741
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...
1
4783
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...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
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...

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.