开发者

Clone a container control and its child controls during runtime [duplicate]

This question already has answers here: Clone Winform control (2 answers) Closed 2 years ago.

I have a Windows Forms container control (e.g. a group box or a panel) with some child controls. Now I want to copy/clone this container control, so that I get a exact copy of it during runtime. How can I achiev开发者_StackOverflow社区e this with C#?

What I want to do it something like this:

GroupBox groupNewBox;
groupBox1.CloneTo(groupNewBox);


Hi The only way for copying an object is to implement IClonable interface. But as far as I know, windows controls do not implement this interface, So you should create your own conrtols derived from the container and child control which will implement IClonable interface.


implement ICloneable with the function like this:

public class NewClass, ICloneable
{


    public object Clone()
            {
                return MemberwiseClone();
            }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜