/// <include file="doc\FormDocumentDesigner.uex" path='docs/doc[@for="FormDocumentDesigner.OnComponentRemoved"]/*'> /// <devdoc> /// Called when a component is removed from the design container. /// Here, we check if a menu is being removed and handle removing /// the Form's mainmenu vs. other menus properly. /// </devdoc> private void OnComponentRemoved(object source, ComponentEventArgs ce) { if (ce.Component is Menu) { //if we deleted the form's mainmenu, set it null... if (ce.Component == Menu) { PropertyDescriptor menuProp = TypeDescriptor.GetProperties(Component)["Menu"]; Debug.Assert(menuProp != null, "What happened to the Menu property"); menuProp.SetValue(Component, null); hasMenu = false; } else if (menuEditorService != null && ce.Component == menuEditorService.GetMenu()) { menuEditorService.SetMenu(Menu); } } //if (ce.Component is ToolStrip && toolStripAdornerWindowService != null) //{ // toolStripAdornerWindowService = null; //} if (ce.Component is IButtonControl) { if (ce.Component == ShadowProperties["AcceptButton"]) { this.AcceptButton = null; } if (ce.Component == ShadowProperties["CancelButton"]) { this.CancelButton = null; } } }
internal virtual void DoProperMenuSelection(ICollection selComponents) { foreach (object obj in selComponents) { if (obj is ContextMenu cm) { menuEditorService.SetMenu((Menu)obj); } else { if (obj is MenuItem item) { //before we set the selection, we need to check if the item belongs the current menu, if not, we need to set the menu editor to the appropiate menu, then set selection MenuItem parent = item; while (parent.Parent is MenuItem) { parent = (MenuItem)parent.Parent; } if (menuEditorService.GetMenu() != parent.Parent) { menuEditorService.SetMenu(parent.Parent); } //ok, here we have the correct editor selected for this item. Now, if there's only one item selected, then let the editor service know, if there is more than one - then the selection was done through themenu editor and we don't need to tell it if (selComponents.Count == 1) { menuEditorService.SetSelection(item); } } //Here, something is selected, but the menuservice isn't interested so, we'll collapse our active menu accordingly else { menuEditorService.SetMenu(null); } } } }