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();
}
}
精彩评论