2017-02-14 4 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; 
    } 
関連する問題