protected virtual void MoveTab(TabPanel from, TabPanel to) { if (!(this.Control is TabView)) { return; } if (from == null || to == null || !this.Control.Controls.Contains(from) || !this.Control.Controls.Contains(to)) { return; } IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost)); TabView tabView = this.Control as TabView; if (designerHost == null) { return; } using (DesignerTransaction transaction = designerHost.CreateTransaction($"Add tab to \"{tabView.Name}\"")) { try { PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)]; this.RaiseComponentChanging(controlsProperty); this.Control.Controls.SetChildIndex(from, Control.Controls.GetChildIndex(to)); this.RaiseComponentChanged(controlsProperty, null, null); tabView.UpdateLayout(); tabView.Refresh(); transaction.Commit(); } catch { transaction.Cancel(); } } }
protected virtual void RemoveTab() { if (!(this.Control is TabView)) { return; } IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost)); TabView tabView = this.Control as TabView; TabPanel tabPanel = null; if (tabView.SelectedTab != null) { tabPanel = tabView.SelectedTab; } if (designerHost == null || tabPanel == null) { return; } using (DesignerTransaction transaction = designerHost.CreateTransaction($"Remove tab from \"{tabView.Name}\"")) { try { PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)]; this.RaiseComponentChanging(controlsProperty); designerHost.DestroyComponent(tabPanel); this.RaiseComponentChanged(controlsProperty, null, null); tabView.UpdateLayout(); tabView.Refresh(); transaction.Commit(); } catch { transaction.Cancel(); } } }
protected virtual void AddTab() { if (!(this.Control is TabView)) { return; } IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost)); TabView tabView = this.Control as TabView; if (designerHost == null) { return; } using (DesignerTransaction transaction = designerHost.CreateTransaction($"Add tab to \"{tabView.Name}\"")) { try { TabPanel tab = (TabPanel)designerHost.CreateComponent(typeof(TabPanel)); PropertyDescriptor controlsProperty = TypeDescriptor.GetProperties(tabView)[nameof(tabView.Controls)]; PropertyDescriptor tabTextProperty = TypeDescriptor.GetProperties(tab)[nameof(tab.Text)]; this.RaiseComponentChanging(controlsProperty); tabView.Controls.Add(tab); this.RaiseComponentChanged(controlsProperty, null, null); tabTextProperty.SetValue(tab, tab.Name); tabView.ShowTab(tab); tabView.UpdateLayout(); tabView.Refresh(); transaction.Commit(); } catch { transaction.Cancel(); } } }