-1
我已經定製了一個TabPage,但發現有如下問題:C#TabControl,如何創建自定義TabPages集合編輯器?
首先,我創建了兩個自定義TabPage,它工作正常。
但是有一個問題,當我關閉文檔,然後重新打開我的文章:
看,TabPage的變四,但我發現這個問題了「designer.cs」文件內。
//
// blK_TabControl1
//
this.blK_TabControl1.Controls.Add(this.blK_TabPage6);
this.blK_TabControl1.Controls.Add(this.blK_TabPage7);
this.blK_TabControl1.Location = new System.Drawing.Point(4, 12);
this.blK_TabControl1.Name = "blK_TabControl1";
this.blK_TabControl1.SelectedIndex = 0;
this.blK_TabControl1.Size = new System.Drawing.Size(604, 196);
this.blK_TabControl1.TabIndex = 14;
this.blK_TabControl1.TabPages.AddRange(new System.Windows.Forms.TabPage[] {
this.blK_TabPage6,
this.blK_TabPage7});
正常的TabControl添加的TabPage後,有沒有 「TabPages.AddRange()」 這個代碼,我怎麼能解決這個問題?
這裏是我的代碼:
public class BLK_TabPageCollectionEditor : CollectionEditor
{
public BLK_TabPageCollectionEditor(Type type)
: base(type)
{
}
protected override bool CanSelectMultipleInstances()
{
return false;
}
protected override Type CreateCollectionItemType()
{
return typeof(BLK_TabPage);
}
protected override object CreateInstance(Type itemType)
{
BLK_TabPage tabPage = (BLK_TabPage)itemType.Assembly.CreateInstance(itemType.FullName);
IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
host.Container.Add(tabPage);
//this.Context.Container.Add(tabPage);
tabPage.Text = tabPage.Name;
return tabPage;
}
}
public class BLK_TabControl : TabControl
{
[EditorAttribute(typeof(BLK_TabPageCollectionEditor), typeof(UITypeEditor))]
[MergableProperty(false)]
public new TabControl.TabPageCollection TabPages
{
get
{
return base.TabPages;
}
}
}
在此先感謝。
您可以考慮使用,而不是與你的第二個圖像的圖像代碼塊。 –