2017-02-14 2 views
0

CreateInstance을 주석 처리하면 "디자인"이 표시됩니다. 그러나 내가 그것을 무시하면 그것은 보이지 않습니다. 어떻게 표시 할 수 있습니까?CreateInstance()를 재정의 할 때 사용자 정의 CollectionEditor에서 "디자인"범주를 표시하는 방법은 무엇입니까?

없음 무시하지 :

enter image description here

오버라이드 :

enter image description here

코드 :

public class MyEditor : CollectionEditor 
{ 
    public MyEditor(Type type) : base(type) 
    { 
    } 

    protected override Type[] CreateNewItemTypes() 
    { 
     return new[] 
     { 
      typeof(TabPage) //TabPage is a subclass of "Panel". 
     }; 
    } 
    protected override object CreateInstance(Type itemType) 
    { 
     var item = new TabPage(true); 
     return item; 
    } 
} 

또한, 컬렉션 편집기 창의 제목이 객체 "입니다 컬렉션 편집기 ", 대신에 내 컬렉션의 이름은 "TabPage Collection Editor"와 같습니다. 큰 문제는 아니지만 가능하면이 문제를 해결하고 싶습니다.

답변

0

예제가 없기 때문에 .NET Framework를 디 컴파일하여 Microsoft에서 어떻게 수행하는지 확인했습니다. Microsoft의 TabPageCollectionEditor은 "System.Design.dll"안에있었습니다. baseCreateInstance을 사용한 다음 결과를 수정하여 추가했습니다.

그래서 다음과 같이 코드를 변경했습니다. 이제 작동합니다. 이 문제를 처음부터 무시하려는 이유는 기본적으로 올바른 페이지 이름을 설정하기 위해서였습니다. 나는 여전히 제목을 "Object ..."에서 "TabPage ..."로 변경하는 방법을 찾지 못했습니다.

protected override object CreateInstance(Type itemType) 
    { 
     var instance = base.CreateInstance(itemType) as TabPage; 

     var control = Context?.Instance as MyTabControl; 
     int currentIndex = control.TabPages.Count; 
     instance.Text = $"Page {currentIndex}"; 

     return instance; 
    } 
관련 문제