Duplicate Group Box

How can I Duplicate a Groupbox in C# window application , the group box contain 30 textbox and i need to duplicate it on a special event and I don't know the maximum number of needed groupbox


If you are using winforms, possible solutions:

  1. Put a groupbox on form, customize it, copy the generated code (from ..designer.cs file) and put it to a method. When you event occurs you just call the method that will create new control.
  2. Using reflection create a new object of the same type and any writable property will get their values copied, use this method:

    private object CloneObject(object o)
        Type t = o.GetType();
        PropertyInfo[] properties = t.GetProperties();
    Object p = t.InvokeMember("", System.Reflection.
        BindingFlags.CreateInstance, null, o, null);
    foreach (PropertyInfo pi in properties)
        if (pi.CanWrite)
            pi.SetValue(p, pi.GetValue(o, null), null);
    return p;

Use it like:

private void button1_Click(object sender, EventArgs e)
GroupBox g = (GroupBox)CloneObject(groupBox1);

Both methods are described here

Need Your Help

PhpMyAdmin Query for WordPress

mysql wordpress phpmyadmin mysql-management

How do I query PhpMyAdmin to delete WordPress comments where the commenter added their website?

Json convert and return a wrong string

c# asp.net json jquery

I have a textbox on asp.net web form. I passed the text into web service by the following code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.