/// <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); }
/// <include file='doc\Menu.uex' path='docs/doc[@for="Menu.ClearHandles"]/*' /> /// <devdoc> /// Notifies Menu that someone called Windows.DeleteMenu on its handle. /// </devdoc> /// <internalonly/> internal void ClearHandles() { UnsafeNativeMethods.DestroyMenu(new HandleRef(this, handle)); handle = IntPtr.Zero; if (created) { for (int i = 0; i < itemCount; i++) { items[i].ClearHandles(); } created = false; } }