복제 된 패널의 자식 컨트롤을 다시 그리는 데 문제가 있습니다.깊이 복제 된 패널; 컨트롤을 다시 그리지 않습니다
먼저 나는 IClonable을 사용하지 않습니다. 나는 반사을 사용하고 있습니다.
내 코드 :
public static Panel ClonePanel(Panel panel)
{
Panel newPanel = (Panel) CloneControl(panel);
foreach (Control ctl in panel.Controls)
{
Control newCtl = CloneControl(ctl);
newCtl.Visible = true;
newPanel.Controls.Add(newCtl);
}
newPanel.Visible = true;
return newPanel;
}
public static Control CloneControl(Control o)
{
Type type = o.GetType();
PropertyInfo[] properties = type.GetProperties();
Control retObject = (Control) type.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, o, null);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.CanWrite)
{
propertyInfo.SetValue(retObject, propertyInfo.GetValue(o, null), null);
}
}
return retObject;
}