EDN Admin
Well-known member
I add my created custom control to the new Windows Form and add some Tab to it by "Tabs" property. However, when I delete my custom control from Windows Form, elements of "Tabs" property are not removed. Please see below figures for more information:
<img alt="My custom control " src="http://social.msdn.microsoft.com/Forums/getfile/183870 <br/>
Figure 1 - My custom control "Tabs" property with its Collection Editor
<ol>
Blue Box: "Tabs" property of my custom controlRed Box: Added elements to the "Tabs" property</ol>
Figure 1 displays when I add some member to the Tabs property.
<img alt="Windows Form project controls after add some member to the Tabs property" src="http://social.msdn.microsoft.com/Forums/getfile/183871 <br/>
Figure 2 - Windows Form project controls after add some member to the Tabs property
<ol>
Red Box: My custom controlBlue Box: Added elements to the Tabs property</ol>
http://social.msdn.microsoft.com/Forums/getfile/183872" target="_blank" title="Windows Form project controls after delete my custom control from Windows Form Figure 3 <br/>
Figure 3 - Windows Form project controls after delete my custom control from Windows Form
Red Box: Added elements to the Tabs property
As you can see in the figure 2 and 3, I add some member to the Tabs property and after delete my custom control from its parent control (Windows Form), Tabs property members have not been removed.
My Tabs property is related to the Tabs class that derived from CollectionBase class and implement some methods such as Add, Remove, Clear and, etc. to it. And I call Clear and RemoveRange methods in the Dispose method, but it doesnt work.
My codes as follows:
<pre class="prettyprint" style=" [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);
}
}
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();
}
}[/code]
<
Regards Mohsen Rostami
<br/>
View the full article
<img alt="My custom control " src="http://social.msdn.microsoft.com/Forums/getfile/183870 <br/>
Figure 1 - My custom control "Tabs" property with its Collection Editor
<ol>
Blue Box: "Tabs" property of my custom controlRed Box: Added elements to the "Tabs" property</ol>
Figure 1 displays when I add some member to the Tabs property.
<img alt="Windows Form project controls after add some member to the Tabs property" src="http://social.msdn.microsoft.com/Forums/getfile/183871 <br/>
Figure 2 - Windows Form project controls after add some member to the Tabs property
<ol>
Red Box: My custom controlBlue Box: Added elements to the Tabs property</ol>
http://social.msdn.microsoft.com/Forums/getfile/183872" target="_blank" title="Windows Form project controls after delete my custom control from Windows Form Figure 3 <br/>
Figure 3 - Windows Form project controls after delete my custom control from Windows Form
Red Box: Added elements to the Tabs property
As you can see in the figure 2 and 3, I add some member to the Tabs property and after delete my custom control from its parent control (Windows Form), Tabs property members have not been removed.
My Tabs property is related to the Tabs class that derived from CollectionBase class and implement some methods such as Add, Remove, Clear and, etc. to it. And I call Clear and RemoveRange methods in the Dispose method, but it doesnt work.
My codes as follows:
<pre class="prettyprint" style=" [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);
}
}
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();
}
}[/code]
<
Regards Mohsen Rostami
<br/>
View the full article