2009-11-21 4 views
0

복제 된 패널의 자식 컨트롤을 다시 그리는 데 문제가 있습니다.깊이 복제 된 패널; 컨트롤을 다시 그리지 않습니다

먼저 나는 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; 
} 

답변

-1

그래서, 내가 대신 훨씬, 훨씬 더 나은 것으로 밝혀졌다 패널의 UserControl을 사용하여 그것을 해결.

내가 추가로 갖고 싶은 것은 해당 디자이너뿐만 아니라 Form 자체에서 UserControl 컨트롤을 디자인하는 것뿐입니다. 그러나 그것은 문제가되지 않습니다. 나는 그걸로 살 수 있습니다.

1

두 번째 문제는 System.Design에 대한 참조를 추가하십시오. 그런 다음 [Deisgner (typeof ( ParentControlDesigner)] 특성을 사용자 정의 컨트롤에 추가하면 디자인 타임에 패널 컨트롤처럼 사용할 수 있습니다 ..

관련 문제