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

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
		protected override void Dispose (bool disposing)
		{
			if (disposing && parent_menu != null)
				parent_menu.MenuItems.Remove (this);
				
			base.Dispose (disposing);			
		}

Usage Example

Example #1
0
        /// <include file='doc\Menu.uex' path='docs/doc[@for="Menu.Dispose"]/*' />
        /// <devdoc>
        ///     Disposes of the component.  Call dispose when the component is no longer needed.
        ///     This method removes the component from its container (if the component has a site)
        ///     and triggers the dispose event.
        /// </devdoc>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                while (ItemCount > 0)
                {
                    MenuItem item = items[--_itemCount];

                    // remove the item before we dispose it so it still has valid state
                    // for undo/redo
                    //
                    if (item.Site != null && item.Site.Container != null)
                    {
                        item.Site.Container.Remove(item);
                    }

                    item.Menu = null;
                    item.Dispose();
                }
                items = null;
            }
            if (handle != IntPtr.Zero)
            {
                UnsafeNativeMethods.DestroyMenu(new HandleRef(this, handle));
                this.handle = IntPtr.Zero;
                if (disposing)
                {
                    ClearHandles();
                }
            }
            base.Dispose(disposing);
        }
All Usage Examples Of System.Windows.Forms.MenuItem::Dispose