作成したカスタム コントロールを新しい Windows フォームに追加し、「タブ」プロパティでいくつかのタブを追加します。ただし、Windows フォームからカスタム コントロールを削除しても、「タブ」プロパティの要素は削除されません。詳細については、以下の図を参照してください。
図 1 - カスタム コントロールの「タブ」プロパティとそのコレクション エディター
- ブルー ボックス: カスタム コントロールの「タブ」プロパティ
- 赤いボックス: 「タブ」プロパティに要素を追加
Tabs プロパティにメンバーを追加すると、図 1 が表示されます。
図 2 - Tabs プロパティにメンバーを追加した後の Windows フォーム プロジェクト コントロール
- 赤いボックス: カスタム コントロール
- ブルー ボックス: タブ プロパティに要素を追加
図 3 - カスタム コントロールを Windows フォームから削除した後の Windows フォーム プロジェクト コントロール
- 赤のボックス: Tabs プロパティに要素を追加
図 2 と 3 でわかるように、いくつかのメンバーを Tabs プロパティに追加し、親コントロール (Windows フォーム) からカスタム コントロールを削除した後、Tabs プロパティ メンバーは削除されていません。
My Tabs プロパティは、CollectionBase クラスから派生した Tabs クラスに関連し、それに Add、Remove、Clear などのメソッドを実装します。そして、Dispose メソッドで Clear メソッドと RemoveRange メソッドを呼び出しますが、機能しません。
次のように私のコード:
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
[ToolboxItem(true), ToolboxBitmap(typeof(ToolboxIconResourceFinder), "FloorsGrouping.bmp")]
[DisplayName("Floors Group")]
[Editor("WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc", typeof(UITypeEditor))]
[Description("Floorssssssss")]
[Category("Saino")]
//[DefaultEvent("")]
[DefaultProperty("Text")]
[DesignerCategory("Component")] //Form //Designer //Empty String ("")
public partial class FloorsGrouping : Bar
{
private static Font fntDefaultFont = SystemFonts.DefaultFont;
private static string strDefaultAccessibleDescription = "";
private static string strDefaultAccessibleName = "";
private bool canDockBottom = false;
private bool canDockTop = false;
private bool fadeEffect = true;
private int selectedDockTab = 0;
private eDotNetBarStyle style = eDotNetBarStyle.StyleManagerControlled;
private string text = "Floors Grouping";
private FloorsInformation floorsInformation = new FloorsInformation();
private Tabs tabs = new Tabs();
private SupportedLanguages language = SupportedLanguages.English;
private Styles groupingStyles = Styles.Classic;
public FloorsGrouping()
{
InitializeComponent();
ResetFont();
ResetAccessibleDescription();
ResetAccessibleName();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
Tab.Clear();
Tab.RemoveRange(0, Tab.Count);
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private new void ResetFont()
{
Font = fntDefaultFont;
}
private new bool ShouldSerializeFont()
{
return !Font.Equals(fntDefaultFont);
}
[Category("Data")]
[DisplayName("Tabs")]
[Description("Tabsssssssssssss")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
//[Editor(typeof(ItemsCollectionEditor<SimilarFloorsInformation>), typeof(UITypeEditor))]
//[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public Tabs Tab
{
get
{
return tabs;
}
}
[Category("Behavior")]
[DisplayName("ContainerControl")]
[Description("It indicates container control high lighter is bound to. It should be set to parent form.")]
//[DefaultValue("")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Browsable(false), ReadOnly(true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public Control ContainerControl
{
get { return hltMain.ContainerControl; }
private set { hltMain.ContainerControl = this; }
}
protected override void OnParentChanged(EventArgs e)
{
ContainerControl = this;
}
protected override void OnCreateControl()
{
base.OnCreateControl();
}
protected override void OnControlRemoved(ControlEventArgs e)
{
//Tab.RemoveRange(0, tabs.Count);
//Parent.Refresh();
base.OnControlRemoved(e);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
[DisplayName("Floors Information")]
[Description("Floors Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("Text")]
[DesignerCategory("Component")]
[ToolboxItem(false)]
public class FloorsInformation : DockContainerItem
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private SimilarFloorsInformation similarFloorsInformation = new SimilarFloorsInformation();
private AllFloorsInformation allFloorsInformation = new AllFloorsInformation();
private string text = "Floors Information";
public FloorsInformation()
{
}
[Browsable(false), ReadOnly(true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new bool AutoCollapseOnClick
{
get { return base.AutoCollapseOnClick; }
}
[Browsable(false), ReadOnly(true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new Control Control
{
get { return base.Control; }
}
public new string Text
{
get
{
return text;
}
set
{
text = value;
}
}
[Category("Data")]
[DisplayName("Similar Floors Panel")]
[Description("Similar Floors Panellllllllllllllllllll")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public SimilarFloorsInformation SimilarFloorsInfo
{
get
{
return similarFloorsInformation;
}
set
{
similarFloorsInformation = value;
}
}
[Category("Data")]
[DisplayName("All Floors Group")]
[Description("All Floors Groupppppppppppppp")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public AllFloorsInformation AllFloorsInfo
{
get
{
return allFloorsInformation;
}
set
{
allFloorsInformation = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
public class Tabs : CollectionBase
{
public FloorsInformation this[int intIndex]
{
get
{
return (FloorsInformation)InnerList[intIndex];
}
set
{
InnerList[intIndex] = value;
}
}
public int Add(FloorsInformation finfItemType)
{
return InnerList.Add(finfItemType);
}
public new void Clear()
{
InnerList.Clear();
}
public bool Contains(FloorsInformation finfItemType)
{
return InnerList.Contains(finfItemType);
}
public void Remove(FloorsInformation finfItemType)
{
InnerList.Remove(finfItemType);
}
public new void RemoveAt(int intIndex)
{
InnerList.RemoveAt(intIndex);
}
public void RemoveRange(int intIndex, int intCount)
{
InnerList.RemoveRange(intIndex, intCount);
}
public void Insert(int intIndex, FloorsInformation finfItemType)
{
InnerList.Insert(intIndex, finfItemType);
}
public void Reverse()
{
InnerList.Reverse();
}
public void Reverse(int intIndex, int intCount)
{
InnerList.Reverse(intIndex, intCount);
}
public int IndexOf(FloorsInformation finfItemType)
{
return InnerList.IndexOf(finfItemType);
}
public void AddRange(FloorsInformation[] finfItemType)
{
InnerList.AddRange(finfItemType);
}
public FloorsInformation[] GetValues()
{
FloorsInformation[] finfItemType = new FloorsInformation[InnerList.Count];
InnerList.CopyTo(0, finfItemType, 0, InnerList.Count);
return finfItemType;
}
protected override void OnInsert(int intIndex, object objValue)
{
base.OnInsert(intIndex, objValue);
}
protected override void OnClear()
{
base.OnClear();
}
}
public class ItemsCollectionEditor : CollectionEditor
{
private Type[] typItems;
public ItemsCollectionEditor(Type typItem)
: base(typItem)
{
typItems = new Type[] { typeof(FloorsInformation) };
}
protected override Type[] CreateNewItemTypes()
{
return typItems;
}
protected override CollectionForm CreateCollectionForm()
{
CollectionForm collectionForm = base.CreateCollectionForm();
collectionForm.Text = "Tabs Collection Editor";
return collectionForm;
//return base.CreateCollectionForm();
}
}
DevComponents.DotNetBar のバー コントロールのようなことをしたいです。詳細については、次を参照してください。
図 4 - バー コントロールを Windows フォームに追加する
- 左の赤いボックス: Windows フォームに追加されたバー コントロール
- 右の赤いボックス: Visual Studio のプロパティ グリッドに追加されたバー コントロール
バー コントロールが Windows フォームに追加されると、図 4 に示すようにプロパティ グリッドが変化します。
図 5 - 「バー タスク」オプションによる Dock タブの作成
- 赤いボックス: [バー タスク] の下の [Dock タブの作成] オプション
図 5 に示すように、[バー タスク] の下の [ドック タブの作成] オプションを使用して、バー コントロールの特定のタブに新しいコントロールを追加するための新しいドック タブを作成できます。
図 6 - 追加された Dock コンテナ アイテムとそれに関連する Panel Dock コンテナ
- 赤いボックス: Visual Studio のプロパティ グリッドに追加されたバー コントロール
- 左の青いボックス: Dock Container Item コントロールを Bar コントロールに追加
- 右の青いボックス: Visual Studio のプロパティ グリッドに Dock Container Item コントロールを追加
- 左の緑のボックス: Panel Dock Container コントロールを Dock Container Item コントロールに追加
- 右の緑のボックス: Visual Studio のプロパティ グリッドに追加された Panel Dock Container コントロール
図 7 - 追加された Dock コンテナ アイテムとそれに関連する Panel Dock コンテナ
- 赤いボックス: 図 6 の赤いボックスを参照してください。
- 左の青いボックス: Dock Container Item コントロールを Bar コントロールに追加
- 右の青いボックス: Visual Studio のプロパティ グリッドに Dock Container Item コントロールを追加
- 右の緑のボックス: Visual Studio のプロパティ グリッドに Panel Dock Container コントロールを追加
[Bar Tasks] の下の [Create Dock Tab] オプションをクリックするたびに、DevComponents.DotNetBar の Bar コントロールに、関連する Panel Dock Container コントロールを含む新しい Dock Container Item コントロールが作成されます (図 6 および 7 を参照してください)。
図 8 - バー コントロールを削除した後の Visual Studio のプロパティ グリッド
- 赤いボックス: Visual Studio のプロパティ グリッドの Windows フォーム コントロール
バー コントロールが Windows フォームから削除されると、それに関連するすべてのコントロールが削除され、Windows フォームだけが残ります。
カスタム コントロールがその親コントロール (Windows フォーム) から削除された後、「タブ」プロパティ メンバーを自動的に削除したいと考えています。