By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,158 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,158 IT Pros & Developers. It's quick & easy.

How to clone container control (with child control inside it) like a group box

P: n/a
I'll make this post as short as possible.

1. Put a GroupBox on a window form. Put a Button and TextBox inside the
GroupBox .
2. Select the group box, do copy and paste inside the same windows form
(or different window form, doesnt matter).
3. Now I have another copy (or clone) of the GroupBox with a Button
and a Texbox control inside it. They have different name (should be
groupBox2, button2 and textBox2).

However I want to do this with code. I try this

----------------------------------------------------------------------
GroupBox groupNewBox = groupBox1;
----------------------------------------------------------------------

But this is groupNewBox is referencing groupBox1.

I can do this,

----------------------------------------------------------------------
GroupBox groupNewBox = new GroupBox();
groupNewBox.Text = groupBox1.Text;
Foreach( Control ctrl in groupBox.Controls)
{
//take each control and manually recreate the
//control as child of groupNewBox
}
----------------------------------------------------------------------

But what I REALLY want todo is something like this

----------------------------------------------------------------------
GroupBox groupNewBox;
groupBox1.CloneTo(groupNewBox);
----------------------------------------------------------------------

Without having to extend GroupBox to something like CloneableGroupBox.

Appreciate any reply to this.

May 18 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.