System.Windows.Forms.ToolStripItem.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
		protected override void Dispose (bool disposing)
		{
			if (!is_disposed && disposing)
				is_disposed = true;

			if (image != null) {
				StopAnimation ();
				image = null;
			}

			if (owner != null)
				owner.Items.Remove (this);
			
			base.Dispose (disposing);
		}
		

Usage Example

 private void RemoveItem(ToolStripItem item)
 {
     int index;
     try
     {
         index = this._itemList.IndexOf(item);
         this._itemList.Remove(item);
     }
     finally
     {
         item.Dispose();
     }
     if (this._itemList.Count > 0)
     {
         this.listBoxItems.ClearSelected();
         index = Math.Max(0, Math.Min(index, this.listBoxItems.Items.Count - 1));
         this.listBoxItems.SelectedIndex = index;
     }
 }