public void AddTab(string filename = "") { if (TabPages.ContainsKey(filename)) { return; } var tabPage = new TabPage(); if (string.IsNullOrEmpty(filename)) { tabPage.Text = Strings.DocumentsTabControl_AddTab_NewFile + id; tabPage.ImageIndex = 1; tabPage.Name = Strings.DocumentsTabControl_AddTab_NewFile + id; } else { tabPage.Text = filename; tabPage.ImageIndex = 0; tabPage.Name = filename; } TabPages.Insert(TabPages.Count - 1, tabPage); SelectedIndex = TabPages.IndexOf(tabPage); id++; }
private void InsertTabPage(System.Windows.Forms.TabPage[] originalOrder, System.Windows.Forms.TabPage page) { if (TabPages.Contains(page)) { return; } if (originalOrder == null) { TabPages.Add(page); } System.Collections.Generic.Dictionary <System.Windows.Forms.TabPage, int> dictionary = new System.Collections.Generic.Dictionary <System.Windows.Forms.TabPage, int>(); for (int i1 = 0; i1 < originalOrder.Length; i1++) { dictionary.Add(originalOrder[i1], i1); } if (!dictionary.ContainsKey(page)) { TabPages.Add(page); } int i2 = dictionary[page];// (page); for (int i3 = 0; i3 < TabPages.Count; i3++) { System.Windows.Forms.TabPage tabPage = TabPages[i3]; if (dictionary.ContainsKey(tabPage) && (dictionary[tabPage] > i2)) { TabPages.Insert(i3, page); return; } } TabPages.Add(page); }
public void AdTabPage(string name, string caption, Color backColr = default(Color), char icon = (char)0, int index = -1) { TabPage tp = new TabPage(name, caption, icon); tp.Parent = this; tp.BackColor = backColr; if (index >= 0 && index < TabPages.Count) { tp.TabIndex = TabPages [index].TabIndex; for (int i = index + 1; i < TabPages.Count; i++) { TabPages [i].TabIndex++; } TabPages.Insert(index, tp); } else { if (TabPages.Count == 0) { tp.TabIndex = 0; } else { tp.TabIndex = TabPages.Last.TabIndex + 1; } TabPages.AddLast(tp); } TabBar.AddChild(tp.TabButton); tp.Selected |= TabPages.Count == 1; ResetCachedLayout(); }
private void SwapTabPages(TabPage src, TabPage dst) { int srcIndex = TabPages.IndexOf(src); int dstIndex = TabPages.IndexOf(dst); if (PlatformHelper.GetPlatform() == Platform.Linux || PlatformHelper.GetPlatform() == Platform.OsX) { TabPages.Insert(dstIndex, src); TabPages.Insert(srcIndex, dst); } else { TabPages[dstIndex] = src; TabPages[srcIndex] = dst; } if (SelectedIndex == srcIndex) { SelectedIndex = dstIndex; } else if (SelectedIndex == dstIndex) { SelectedIndex = srcIndex; } Refresh(); }
internal void ShowTab(TabPage tab, bool show) { var(index, bt) = FindBackingTab(tab, indexVisibleOnly: true); if (index < 0 || bt == null) { return; } if (show) { bt.Visible = true; if (!TabPages.Contains(bt.Tab)) { TabPages.Insert(Math.Min(index, TabCount), bt.Tab); } } else { bt.Visible = false; if (TabPages.Contains(bt.Tab)) { TabPages.Remove(bt.Tab); } } }
/// <summary> /// On drag and drop, we updates the tab order. /// </summary> /// <param name="drgevent"></param> protected override void OnDragDrop(DragEventArgs drgevent) { TabPage draggedTab = GetDraggedTab(drgevent); m_lastPoint = new Point(Int32.MaxValue, Int32.MaxValue); m_markerIndex = -1; UpdateMarker(); // Retrieve the point in client coordinates Point pt = new Point(drgevent.X, drgevent.Y); pt = PointToClient(pt); // Get the tab we are hovering over. bool onLeft; int markerIndex = GetMarkerIndex(draggedTab, pt, out onLeft); int index = GetInsertionIndex(markerIndex, onLeft); // Make sure there is a TabPage being dragged. if (draggedTab == null) { drgevent.Effect = DragDropEffects.None; base.OnDragDrop(drgevent); return; } // Retrieve the dragged page. If same as dragged page, return int draggedIndex = TabPages.IndexOf(draggedTab); if (draggedIndex == index || (draggedIndex == index - 1 && onLeft)) { drgevent.Effect = DragDropEffects.None; base.OnDragDrop(drgevent); return; } // Move the tabs drgevent.Effect = DragDropEffects.Move; this.SuspendDrawing(); SuspendLayout(); try { if (TabPages.IndexOf(draggedTab) < index) { index--; } TabPages.Remove(draggedTab); TabPages.Insert(index, draggedTab); SelectedTab = draggedTab; } finally { ResumeLayout(false); this.ResumeDrawing(); base.OnDragDrop(drgevent); } }
public void ShowPage(TabPage tabPage) { if (HiddenPages.Contains(tabPage)) { int i = HiddenPages.FindIndex(x => x == tabPage); TabPages.Insert(i, tabPage); HiddenPages.RemoveAt(lastIndex[i]); lastIndex.RemoveAt(i); } }
//------------------------------------------------------------------------------------------------------------- protected override void OnDragOver(System.Windows.Forms.DragEventArgs e) { base.OnDragOver(e); Point pt = new Point(e.X, e.Y); //We need client coordinates. pt = PointToClient(pt); //Get the tab we are hovering over. TabPage hover_tab = GetTabPageByTab(pt); //Make sure we are on a tab. if (hover_tab != null) { //Make sure there is a TabPage being dragged. if (e.Data.GetDataPresent(typeof(TabPage))) { e.Effect = DragDropEffects.Move; TabPage drag_tab = (TabPage)e.Data.GetData(typeof(TabPage)); if (drag_tab == GetRealTabPageByTab(pt)) { clearTabRect(); } int item_drag_index = FindIndex(drag_tab); int drop_location_index = FindIndex(hover_tab); //Don't do anything if we are hovering over ourself. if (item_drag_index != drop_location_index) { DraggableTabControl dragOwner = this; if (drag_tab.Parent != this) { dragOwner = drag_tab.Parent as DraggableTabControl; } if (dragOwner != null) { dragOwner.TabPages.Remove(drag_tab); TabPages.Insert(drop_location_index, drag_tab); SelectedTab = drag_tab; } } if (OnTabDropped != null) { OnTabDropped(this, e); } } } else { e.Effect = DragDropEffects.None; } }
public void InsertPage(int index, Control page, Image icon) { TabPages.Insert(index, page); if (icon != null) { var tabItem = TabBar.Items.Find(it => it.Tag == page); if (tabItem != null) { tabItem.Icon = icon; } } }
/// <summary> /// Adds a new, empty page to the tab control. /// </summary> /// <returns> /// The <see cref="RichTextBoxTabPage" /> that was added. /// </returns> public RichTextBoxTabPage AddTab() { RichTextBoxTabPage tab = new RichTextBoxTabPage(); if (TabCount == 0) { TabPages.Insert(TabCount, tab); } else { TabPages.Insert(TabCount - 1, tab); } this.SelectedTab = tab; return(tab); }
/// <summary> /// Adds a new, empty page to the tab control. /// </summary> /// <returns> /// The <see cref="WebBrowserTabPage" /> that was added. /// </returns> public WebBrowserTabPage AddTab() { WebBrowserTabPage tab = new WebBrowserTabPage(); if (TabCount == 0) { TabPages.Insert(TabCount, tab); } else { TabPages.Insert(TabCount - 1, tab); } this.SelectedTab = tab; return(tab); }
public void ShowTab(TabPage page) { if (page != null) { if (_TabPages != null) { if (!TabPages.Contains(page) && _TabPages.Contains(page)) { // Get insert point from backup of pages int pageIndex = _TabPages.IndexOf(page); if (pageIndex > 0) { int start = pageIndex - 1; // Check for presence of earlier pages in the visible tabs for (int index = start; index >= 0; index--) { if (TabPages.Contains(_TabPages[index])) { // Set insert point to the right of the last present tab pageIndex = TabPages.IndexOf(_TabPages[index]) + 1; break; } } } // Insert the page, or add to the end if ((pageIndex >= 0) && (pageIndex < TabPages.Count)) { TabPages.Insert(pageIndex, page); } else { TabPages.Add(page); } } } else { // If the page is not found at all then just add it if (!TabPages.Contains(page)) { TabPages.Add(page); } } } }
/// <summary> /// Creates a new ProfileViewControl in a new tab. /// Reminder: If the tab is not selected after creation, the control's initialization is postponed! /// "Controls contained in a TabPage are not created until the tab page is shown, /// and any data bindings in these controls are not activated until the tab page is shown." /// Microsoft - https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tabpage?view=netframework-4.8 /// </summary> /// <returns>Created instance</returns> public ProfileViewControl ProfileTabCreate() { // Workaround: TabPage size calculation incorrect... // - first tab when created programmatically during Form init uses wrong TabPage size // - one can see then halting with debugger at next code line that tab sizes are different // - selected tab has correct size, info from: https://stackoverflow.com/questions/56242122/c-sharp-winforms-tabpage-size-and-clientsize-wrong // (same issue:) https://stackoverflow.com/questions/29939232/anchor-failed-with-tab-page // (same issue:) https://social.msdn.microsoft.com/Forums/en-US/6fa5e92a-8ab1-41cb-a348-23a8f3bad48c/problem-with-anchor-in-a-inherited-user-control?forum=netfxcompact // Solution here: force Size of all tabs to be equal when creating a new one // (from: https://stackoverflow.com/questions/56242122/c-sharp-winforms-tabpage-size-and-clientsize-wrong ) System.Drawing.Size same = SelectedTab.Size; for (int i = TabPages.Count - 1; 0 <= i; i--) { TabPages[i].Size = same; } for (int i = TabPages.Count - 1; 0 <= i; i--) { if (TabPages[i].Text.Equals("+")) // Search for "New" tab { Control template = TabPages[i - 1].Controls["pvc"]; // Reuse the "New" tab for the actual new page and create an new "New" tab (skips tab selection) TabPages[i].Text = (i + 1).ToString(); // Fill controls of the tab ProfileViewControl pvc_new = new ProfileViewControl(); pvc_new.Anchor = template.Anchor; pvc_new.Location = template.Location; pvc_new.Name = "pvc"; pvc_new.Size = template.Size; pvc_new.TabIndex = 0; pvc_new.ProfileInfo.ProfileChanged += PVC_ProfileChangedHandler; pvc_new.SelectedProfileChanged += PVC_SelectedProfileChangedHandler; pvc_new.UpdateDarkMode(); TabPages[i].Controls.Add(pvc_new); TabPages.Insert(i + 1, "+"); TabPages[i + 1].ToolTipText = TabPages[i].ToolTipText; TabPages[i].ToolTipText = null; ProfileTabSelectedHandler(pvc_new, ProfileTabSelectAction.Created); return(pvc_new); } } return(null); }
public void AddTab(MvcControl mvcControl) { Debug.Assert(m_isInitialized, "Still not initialized"); MvcTabPage tabPage = new MvcTabPage(this, mvcControl); tabPage.VisibleChanged += OnTabVisibleChanged; int index = FindIndexToInsert(tabPage); TabPages.Insert(index, tabPage); tabPage.Initialize(); m_tabPages.Add(tabPage); }
private void OnTabVisibleChanged(object sender, EventArgs e) { Debug.Assert(sender != null && sender is MvcTabPage); MvcTabPage tabPage = (MvcTabPage)sender; if (!tabPage.Visible) { TabPages.Remove(tabPage); } else //from non visible to visible: need to insert { int index = FindIndexToInsert(tabPage); TabPages.Insert(index, tabPage); } }
public void ShowTabPageByName(string tabPageName) { if (tabPagesHidden.ContainsKey(tabPageName)) { System.Windows.Forms.TabPage tabPageToShow; // Get the TabPage object tabPageToShow = tabPagesHidden[tabPageName]; // Add the TabPage to the TabPages collection of the TabControl TabPages.Insert(GetTabPageInsertionPoint(tabPageName), tabPageToShow); // Remove the TabPage from the internal List tabPagesHidden.Remove(tabPageName); } }
/// <summary> /// Creates tabs from a list of property sets. /// </summary> /// <param name="propertySets">Property sets to base tabs off of.</param> public void ApplyPropertySets(List <PropertySet> propertySets) { var tmp = Handle; // Forces creation of window handle so that tabs will appear foreach (PropertySet p in propertySets) { ComponentPropertiesTabPage newPage = new ComponentPropertiesTabPage(this, p.PropertySetID); newPage.ChildForm.Collider = p.Collider; newPage.ChildForm.Friction = p.Friction; newPage.ChildForm.Mass = p.Mass; TabPages.Insert(TabPages.Count - 1, newPage); } SelectedTab = TabPages[0]; }
private void MouseMoveHandler(object sender, MouseEventArgs e) { if (null == TabPageDragDrop) { return; // No DragDrop currently active } if (e.Button != MouseButtons.Left) { // Should be coverd by MouseUp, just for safety // DragDrop stopped TabPageDragDrop = null; } else { // During DragDrop TabPage hover_Tab = GetTabUnderMouse(); if ((hover_Tab == null) || (hover_Tab == TabPageDragDrop)) { return; // Dragged onto nothing or itself? } if (hover_Tab.Text.Equals("+") || hover_Tab.Text.Equals("-")) { return; // Keep "New"/"Delete" tab at the end } // Switch tabs but retain numbering int Index1 = TabPages.IndexOf(TabPageDragDrop); int Index2 = TabPages.IndexOf(hover_Tab); ProfileTabPermutingHandler(this, new Tuple <int, int>(Index1, Index2)); // How to swtich tabs... // - Just overwrite the references to the pages at the specific indicies: // On Windows working solution but will remove entries using Mono. // TabPages[Index1] = hover_Tab; // TabPages[Index2] = TabPageDragDrop; // - Modifying index of one to move it around: // On Mono working solution, but on Windows it seems it does not update order in TabPages // Controls.SetChildIndex(hover_Tab, Index1); // - Be pragmatic and remove one tab and insert it at the new position again: works.. TabPages.RemoveAt(Index1); TabPages.Insert(Index2, TabPageDragDrop); hover_Tab.Text = (Index1 + 1).ToString(); TabPageDragDrop.Text = (Index2 + 1).ToString(); SelectedTab = TabPageDragDrop; } }
private void TabControlEx_MouseDown(object sender, MouseEventArgs e) { if (TabCount == 0) { return; } var lastIndex = TabCount - 1; if (GetTabRect(lastIndex).Contains(e.Location)) { var newTabPage = new TabPage(); if (TabPageAdding != null && TabPageAdding(this, new TabPageEventArgs(newTabPage))) { TabPages.Insert(lastIndex, newTabPage); SelectedIndex = lastIndex; TabPages[lastIndex].UseVisualStyleBackColor = true; } } else { for (var i = 0; i < TabPages.Count; i++) { var tabRect = GetTabRect(i); tabRect.Inflate(-2, -2); var closeImage = Properties.Resources.Close; var imageRect = new Rectangle( (tabRect.Right - closeImage.Width), tabRect.Top + (tabRect.Height - closeImage.Height) / 2, closeImage.Width, closeImage.Height); if (imageRect.Contains(e.Location)) { if (TabPageDeleting != null && TabPageDeleting(this, new TabPageEventArgs(TabPages[i]))) { TabPages.RemoveAt(i); } break; } } } }
private void Swap(TabPage a, TabPage b) { int iA = TabPages.IndexOf(a); int iB = TabPages.IndexOf(b); int d = GetTabRect(iA).Width - GetTabRect(iB).Width; if (tabsSwapped != null) { tabsSwapped(this, new TabsSwappedEventArgs(iA, iB)); } TabPages.RemoveAt(iB); TabPages.Insert(iA, b); if (d < -1) { Cursor.Position = new Point((iA > iB) ? Cursor.Position.X + d : Cursor.Position.X - d, Cursor.Position.Y); } }
protected override void OnDragOver(DragEventArgs e) { base.OnDragOver(e); Point p = PointToClient(new Point(e.X, e.Y)); TabPage hoverTab = TabPageFromPoint(p); TabPage dragTab = (TabPage)e.Data.GetData(typeof(TabPage)); if (hoverTab != null && dragTab != null) { e.Effect = DragDropEffects.Move; int hoverIndex = TabPages.IndexOf(hoverTab); int dragIndex = TabPages.IndexOf(dragTab); if (hoverIndex != dragIndex && (hoverIndex <dragIndex?_dragEntryPoint.X> p.X : _dragEntryPoint.X < p.X)) { _dragEntryPoint = p; TabPages.Remove(dragTab); TabPages.Insert(hoverIndex, dragTab); SelectedTab = dragTab; } } }
/// <summary> /// Undocks a tab page. Returns true if the operation succeeded, otherwise false. /// </summary> public bool Undock(MdiTabPage mdiTabPage) { if (RequestUndock != null) { // To be able to restore state. int oldActiveTabPageIndex = ActiveTabPageIndex; int removedTabPageIndex = TabPages.IndexOf(mdiTabPage); if (TabPages.Remove(mdiTabPage)) { // Set Visible to true in case an inactive tab page is undocked. mdiTabPage.ClientControl.Visible = true; // Redraw immediately before waiting for the end of the any caller. // Necessary because moving the Control to a different parent is going to force an update as well. Update(); // Call the handler and check if the previously docked Control has been properly reparented. RequestUndock(mdiTabPage); if (mdiTabPage.ClientControl.Parent == null) { // Restore original state. TabPages.Insert(removedTabPageIndex, mdiTabPage); if (oldActiveTabPageIndex == removedTabPageIndex) { ActivateTab(oldActiveTabPageIndex); } return(false); } return(true); } } return(false); }
protected override void OnDragDrop(DragEventArgs drgevent) { base.OnDragDrop(drgevent); if (drgevent.Data.GetDataPresent(typeof(TabPage))) { drgevent.Effect = DragDropEffects.Move; TabPage dragTab = (TabPage)drgevent.Data.GetData(typeof(TabPage)); if (ActiveTab == dragTab) { return; } // Capture insert point and adjust for removal of tab // We cannot assess this after removal as differeing tab sizes will cause // inaccuracies in the activeTab at insert point. int insertPoint = ActiveIndex; if (dragTab.Parent.Equals(this) && TabPages.IndexOf(dragTab) < insertPoint) { insertPoint--; } if (insertPoint < 0) { insertPoint = 0; } // Remove from current position (could be another tabcontrol) ((TabControl)dragTab.Parent).TabPages.Remove(dragTab); // Add to current position TabPages.Insert(insertPoint, dragTab); SelectedTab = dragTab; // deal with hidden tab handling? } }
/// <summary> /// Adds a ComponentPropertiesTab if the EnterNameDialog returns OK and the name isn't already taken. /// </summary> /// <returns>true if OK is pressed</returns> public bool AddComponentPropertiesTab() { EnterNameDialog nameDialog = new EnterNameDialog(); if (nameDialog.ShowDialog(this).Equals(DialogResult.OK)) { if (TabPages.ContainsKey(nameDialog.nameTextBox.Text)) { MessageBox.Show("Name is already taken.", "Invalid name."); return(false); } else { ComponentPropertiesTabPage page = new ComponentPropertiesTabPage(this, nameDialog.nameTextBox.Text); TabPages.Insert(TabPages.Count - 1, page); SelectedTab = page; return(true); } } else { return(false); } }
public void AddTab(int index, TabPage page) { TabPages.Insert(index, page); }
// MAY return null! private TabPage CreateTab(PanelInformation.PanelIDs ptype, string name, int dn, int posindex, bool dotheme) { UserControls.UserControlCommonBase uccb = PanelInformation.Create(ptype); // must create, since its a ptype. if (uccb == null) // if ptype is crap, it returns null.. catch { return(null); } uccb.Dock = System.Windows.Forms.DockStyle.Fill; // uccb has to be fill, even though the VS designer does not indicate you need to set it.. copied from designer code uccb.Location = new System.Drawing.Point(3, 3); if (dn == -1) // if work out display number { List <int> idlist = (from TabPage p in TabPages where p.Controls[0].GetType() == uccb.GetType() select(p.Controls[0] as UserControls.UserControlCommonBase).displaynumber).ToList(); if (!idlist.Contains(UserControls.UserControlCommonBase.DisplayNumberPrimaryTab)) { dn = UserControls.UserControlCommonBase.DisplayNumberPrimaryTab; } else { // search for empty id. for (int i = UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs; i <= UserControls.UserControlCommonBase.DisplayNumberStartExtraTabsMax; i++) { if (!idlist.Contains(i)) { dn = i; break; } } } } //System.Diagnostics.Debug.WriteLine("Create tab {0} dn {1} at {2}", ptype, dn, posindex); int numoftab = (dn == UserControls.UserControlCommonBase.DisplayNumberPrimaryTab) ? 0 : (dn - UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs + 1); if (uccb is UserControls.UserControlContainerSplitter && numoftab > 0) // so history is a splitter, so first real splitter will be dn=100, adjust for it { numoftab--; } string postfix = numoftab == 0 ? "" : "(" + numoftab.ToStringInvariant() + ")"; string title = name != null ? name : (PanelInformation.GetPanelInfoByPanelID(ptype).WindowTitle + postfix); uccb.Name = title; // for debugging use TabPage page = new TabPage(title); page.Location = new System.Drawing.Point(4, 22); // copied from normal tab creation code page.Padding = new System.Windows.Forms.Padding(3); page.Controls.Add(uccb); TabPages.Insert(posindex, page); //Init control after it is added to the form uccb.Init(eddiscovery, dn); // start the uccb up if (dotheme) // only user created ones need themeing { EDDTheme.Instance.ApplyToControls(page, applytothis: true); } return(page); }
protected override void OnMouseMove(MouseEventArgs e) { if (_dragTab != null && !_dragging) { var tabBounds = GetTabRect(TabPages.IndexOf(_dragTab)); var delta = tabBounds.X - e.Location.X - _dragOffset; if (Math.Abs(delta) > DragTreshold) { _dragging = true; _hoverTab = -1; _hoverButton = -1; Invalidate(); } } else if (_dragging) { var hoverTab = GetTabFromXCoordinate(e.Location); if (hoverTab >= 0 && hoverTab != _previousDragIndex) { if (TabPages.IndexOf(_dragTab) != hoverTab) { BeginTabUpdates(); // TODO: Just reorder tab drawing instead of the actual tab pages (until mouseup) for better performance TabPages.Remove(_dragTab); TabPages.Insert(hoverTab, _dragTab); SelectedIndex = hoverTab; EndTabUpdates(); } _previousDragIndex = GetTabFromCoordinates(e.Location); // Prevents "flashing" due to uneven tab widths } Invalidate(); } else { var hoverTab = GetTabFromCoordinates(e.Location); if (hoverTab != _hoverTab) { if (_hoverTab != -1 && _hoverTab < TabCount) { Invalidate(GetTabRect(_hoverTab), false); } _hoverTab = hoverTab; if (_hoverTab != -1) { Invalidate(GetTabRect(_hoverTab), false); } } var hover = GetTabButtonFromCoordinates(e.Location); if (hover != _hoverButton) { if (_hoverButton != -1 && _hoverButton < TabCount) { Invalidate(GetTabRect(_hoverButton), false); } _hoverButton = hover; if (_hoverButton != -1) { Invalidate(GetTabRect(_hoverButton), false); } } } base.OnMouseMove(e); }
public void OnUpdateMediaScreens() { // playlist ------------------- MediaScreen mediaScreen = MediaScreen.Playlist; bool show = ((ProTONEConfig.ShowMediaScreens & mediaScreen) == mediaScreen); TabPage tp = GetPageContainingControl(PlaylistScreen); if (show == false && tp != null) { TabPages.Remove(tp); } else if (show == true && tp == null) { int idx = FindIndexForInsert(PlaylistScreen); OPMTabPage otp = new OPMTabPage("TXT_PLAYLIST", this.PlaylistScreen); otp.BackColor = Color.Red; otp.ImageIndex = 0; if (idx >= TabPages.Count) { TabPages.Add(otp); } else { TabPages.Insert(idx, otp); } } // track info ------------------- mediaScreen = MediaScreen.TrackInfo; show = ((ProTONEConfig.ShowMediaScreens & mediaScreen) == mediaScreen); tp = GetPageContainingControl(TrackInfoScreen); if (show == false && tp != null) { TabPages.Remove(tp); } else if (show == true && tp == null) { int idx = FindIndexForInsert(TrackInfoScreen); OPMTabPage otp = new OPMTabPage("TXT_TRACKINFO", this.TrackInfoScreen); otp.ImageIndex = 1; if (idx >= TabPages.Count) { TabPages.Add(otp); } else { base.TabPages.Insert(idx, otp); } } // signal analisys ------------------- mediaScreen = MediaScreen.SignalAnalisys; show = ((ProTONEConfig.ShowMediaScreens & mediaScreen) == mediaScreen); tp = GetPageContainingControl(SignalAnalysisScreen); if (show == false && tp != null) { TabPages.Remove(tp); } else if (show == true && tp == null) { int idx = FindIndexForInsert(SignalAnalysisScreen); OPMTabPage otp = new OPMTabPage("TXT_SIGNALANALYSIS", this.SignalAnalysisScreen); otp.ImageIndex = 2; if (idx >= TabPages.Count) { TabPages.Add(otp); } else { base.TabPages.Insert(idx, otp); } } // bookmarks ------------------- mediaScreen = MediaScreen.BookmarkInfo; show = ((ProTONEConfig.ShowMediaScreens & mediaScreen) == mediaScreen); tp = GetPageContainingControl(BookmarkScreen); if (show == false && tp != null) { TabPages.Remove(tp); } else if (show == true && tp == null) { int idx = FindIndexForInsert(BookmarkScreen); OPMTabPage otp = new OPMTabPage("TXT_BOOKMARKS", this.BookmarkScreen); otp.ImageIndex = 3; if (idx >= TabPages.Count) { TabPages.Add(otp); } else { base.TabPages.Insert(idx, otp); } } ResizeTabPages(); Translator.TranslateControl(this, DesignMode); }
// MAY return null! private TabPage CreateTab(PanelInformation.PanelIDs ptype, string name, int dn, int posindex) { // debug - create an example tab page // keep for now //TabPage page = new TabPage(); //page.Location = new System.Drawing.Point(4, 22); // copied from normal tab creation code //page.Padding = new System.Windows.Forms.Padding(3); //UserControl uc = new UserControl(); //uc.Dock = DockStyle.Fill; //uc.AutoScaleMode = AutoScaleMode.Inherit; //page.Controls.Add(uc); //ExtendedControls.TabStrip ts = new ExtendedControls.TabStrip(); //ts.Dock = DockStyle.Fill; //uc.Controls.Add(ts); //TabPages.Insert(posindex, page); UserControls.UserControlCommonBase uccb = PanelInformation.Create(ptype); // must create, since its a ptype. if (uccb == null) // if ptype is crap, it returns null.. catch { return(null); } uccb.AutoScaleMode = AutoScaleMode.Inherit; // inherit will mean Font autoscale won't happen at attach uccb.Dock = System.Windows.Forms.DockStyle.Fill; // uccb has to be fill, even though the VS designer does not indicate you need to set it.. copied from designer code uccb.Location = new System.Drawing.Point(3, 3); if (dn == -1) // if work out display number { List <int> idlist = (from TabPage p in TabPages where p.Controls[0].GetType() == uccb.GetType() select(p.Controls[0] as UserControls.UserControlCommonBase).displaynumber).ToList(); if (!idlist.Contains(UserControls.UserControlCommonBase.DisplayNumberPrimaryTab)) { dn = UserControls.UserControlCommonBase.DisplayNumberPrimaryTab; } else { // search for empty id. for (int i = UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs; i <= UserControls.UserControlCommonBase.DisplayNumberStartExtraTabsMax; i++) { if (!idlist.Contains(i)) { dn = i; break; } } } } //System.Diagnostics.Debug.WriteLine("Create tab {0} dn {1} at {2}", ptype, dn, posindex); int numoftab = (dn == UserControls.UserControlCommonBase.DisplayNumberPrimaryTab) ? 0 : (dn - UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs + 1); if (uccb is UserControls.UserControlContainerSplitter && numoftab > 0) // so history is a splitter, so first real splitter will be dn=100, adjust for it { numoftab--; } string postfix = numoftab == 0 ? "" : "(" + numoftab.ToStringInvariant() + ")"; string title = name != null ? name : (PanelInformation.GetPanelInfoByPanelID(ptype).WindowTitle + postfix); uccb.Name = title; // for debugging use TabPage page = new TabPage(title); page.Location = new System.Drawing.Point(4, 22); // copied from normal tab creation code page.Padding = new System.Windows.Forms.Padding(3); // this is to allow a pad around the sides page.Controls.Add(uccb); TabPages.Insert(posindex, page); // with inherit above, no font autoscale //Init control after it is added to the form uccb.Init(eddiscovery, dn); // start the uccb up uccb.Scale(this.FindForm().CurrentAutoScaleFactor()); // scale and EDDTheme.Instance.ApplyStd(page); // theme it. Order as per the contract in UCCB return(page); }
// MAY return null! private TabPage CreateTab(PanelInformation.PanelIDs ptype, string name, int dn, int posindex, bool dotheme) { UserControls.UserControlCommonBase uccb = PanelInformation.Create(ptype); // must create, since its a ptype. if (uccb == null) // if ptype is crap, it returns null.. catch { return(null); } uccb.Dock = System.Windows.Forms.DockStyle.Fill; // uccb has to be fill, even though the VS designer does not indicate you need to set it.. copied from designer code uccb.Location = new System.Drawing.Point(3, 3); List <int> idlist = (from TabPage p in TabPages where p.Controls[0].GetType() == uccb.GetType() select(p.Controls[0] as UserControls.UserControlCommonBase).displaynumber).ToList(); if (dn == -1) // if work out display number { // not travel grid (due to clash with History control) and not in list, use primary number (0) if (ptype != PanelInformation.PanelIDs.TravelGrid && !idlist.Contains(UserControls.UserControlCommonBase.DisplayNumberPrimaryTab)) { dn = UserControls.UserControlCommonBase.DisplayNumberPrimaryTab; } else { // search for empty id. for (int i = UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs; i <= UserControls.UserControlCommonBase.DisplayNumberStartExtraTabsMax; i++) { if (!idlist.Contains(i)) { dn = i; break; } } } } System.Diagnostics.Debug.WriteLine("Create tab {0} dn {1} at {2}", ptype, dn, posindex); uccb.Init(eddiscovery, travelgrid, dn); // start the uccb up string postfix; if (ptype != PanelInformation.PanelIDs.TravelGrid) // given the dn, work out the name { postfix = (dn == UserControls.UserControlCommonBase.DisplayNumberPrimaryTab) ? "" : "(" + (dn - UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs + 1).ToStringInvariant() + ")"; } else { postfix = (dn == UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs) ? "" : "(" + (dn - UserControls.UserControlCommonBase.DisplayNumberStartExtraTabs).ToStringInvariant() + ")"; } string title = name != null ? name : (PanelInformation.GetPanelInfoByEnum(ptype).WindowTitle + postfix); TabPage page = new TabPage(title); page.Location = new System.Drawing.Point(4, 22); // copied from normal tab creation code page.Padding = new System.Windows.Forms.Padding(3); page.Controls.Add(uccb); TabPages.Insert(posindex, page); if (dotheme) // only user created ones need themeing { EDDTheme.Instance.ApplyToControls(page, applytothis: true); } return(page); }