473,387 Members | 1,388 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,387 software developers and data experts.

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 12024
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.