public void RemovePanel() { int oldIndex = this.layout.ExpandedPanelIndex; if (this.layout.ExpandedPanelIndex > -1) { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); if (host != null) { using (DesignerTransaction dt = host.CreateTransaction("Remove Panel")) { IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); PanelBase panel = this.layout.Items[oldIndex] as PanelBase; try { changeService.OnComponentChanging(this.layout, TypeDescriptor.GetProperties(this.layout)["Items"]); this.layout.Items.Remove(panel); if (this.layout.Items.Count > 0) { PanelBase activeItem = this.layout.Items[Math.Min(oldIndex, this.layout.Items.Count - 1)] as PanelBase; this.ExpandItem(activeItem); } } finally { changeService.OnComponentChanged(this.layout, TypeDescriptor.GetProperties(this.layout)["Items"], null, null); } panel.Dispose(); this.UpdateDesignTimeHtml(); dt.Commit(); } this.Tag.SetDirty(true); } } }
internal void RemoveActiveTab() { if (ActiveTabIndexIsValid) { int oldIndex = this.tabPanelControl.ActiveTabIndex; IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); if (host != null) { using (DesignerTransaction dt = host.CreateTransaction("Remove Active Tab")) { IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); PanelBase activeTab = this.tabPanelControl.Items[this.tabPanelControl.ActiveTabIndex] as PanelBase; try { changeService.OnComponentChanging(this.tabPanelControl, TypeDescriptor.GetProperties(this.tabPanelControl)["Tabs"]); this.tabPanelControl.Items.Remove(activeTab); } finally { changeService.OnComponentChanged(this.tabPanelControl, TypeDescriptor.GetProperties(this.tabPanelControl)["Tabs"], null, null); } activeTab.Dispose(); if (this.tabPanelControl.Items.Count > 0) { PropertyDescriptor activeTabIndex = TypeDescriptor.GetProperties(this.tabPanelControl)["ActiveTabIndex"]; activeTabIndex.SetValue(this.tabPanelControl, Math.Min(oldIndex, this.tabPanelControl.Items.Count - 1)); this.tabPanelControl.ActiveTabIndex = Math.Min(oldIndex, this.tabPanelControl.Items.Count - 1); } UpdateDesignTimeHtml(); dt.Commit(); } this.Tag.SetDirty(true); } } }