private void popoutForm_FormClosing(object sender, FormClosingEventArgs e) { // get the page back var temp = ((Form)sender).Tag as BackstageViewPage; // add back to where it belongs this.pnlPages.Controls.Add(temp.Page); // clear the controls, so we dont dispose the good control when it closes ((Form)sender).Controls.Clear(); popoutPage = null; }
private bool PageHasChildren(BackstageViewPage parent) { // check for children foreach (BackstageViewPage child in _items) { if (child.GetType() == typeof(BackstageViewPage)) { if (((BackstageViewPage)child).Parent == parent) { return(true); } } } return(false); }
private void CreateLinkButton(BackstageViewPage page, bool haschild = false, bool child = false) { if (!page.Show) { return; } string label = page.LinkText; int heightextra = 0; if (haschild) { label = ">> " + label; } if (child) { int count = label.Split('\n').Count(); label = " " + label.Replace("\n", "\n "); heightextra = 15 * (count - 1); } var lnkButton = new BackstageViewButton { Text = label, Tag = page, Top = ButtonTopPos, // Top = _items.TakeWhile(i => i != page).Sum(i => i.Spacing), Width = this.pnlMenu.Width, Height = ButtonHeight + heightextra, ContentPageColor = this.BackColor, PencilBorderColor = _buttonsAreaPencilColor, SelectedTextColor = _selectedTextColor, UnSelectedTextColor = _unSelectedTextColor, HighlightColor1 = _highlightColor1, HighlightColor2 = _highlightColor2, //Dock = DockStyle.Bottom }; pnlMenu.Controls.Add(lnkButton); lnkButton.Click += this.ButtonClick; lnkButton.DoubleClick += lnkButton_DoubleClick; ButtonTopPos += lnkButton.Height; pnlMenu.Invalidate(); }
public int IndexOf(BackstageViewPage itemType) { return(List.IndexOf(itemType)); }
public void Insert(int index, BackstageViewPage itemType) { List.Insert(index, itemType); }
public void Remove(BackstageViewPage itemType) { List.Remove(itemType); }
public int Add(BackstageViewPage itemType) { return(List.Add(itemType)); }
public bool Contains(BackstageViewPage itemType) { return(List.Contains(itemType)); }
public void ActivatePage(BackstageViewPage associatedPage) { if (associatedPage == null) { if (associatedPage.Page == null) { return; } if (_activePage == null) { DrawMenu(null, true); } return; } Tracking?.Invoke(associatedPage.Page.GetType().ToString(), associatedPage.LinkText); this.SuspendLayout(); associatedPage.Page.SuspendLayout(); DrawMenu(associatedPage, false); // Deactivate old page if (_activePage != null && _activePage.Page is IDeactivate) { try { ((IDeactivate)(_activePage.Page)).Deactivate(); } catch (Exception ex) { log.Error(ex); } } // deactivate the old page - obsolete way of notifying activation //_activePage.Page.Close(); if (_activePage != null && _activePage.Page != null) { _activePage.Page.Visible = false; } try { // if the button was on an expanded tab. when we leave it no longer exits if (_activePage != null) { var oldButton = this.pnlMenu.Controls.OfType <BackstageViewButton>().Single(b => b.Tag == _activePage); oldButton.IsSelected = false; } } catch (Exception ex) { log.Error(ex); } associatedPage.Page.ResumeLayout(false); this.ResumeLayout(false); // show it associatedPage.Page.Visible = true; if (!pnlPages.Controls.Contains(associatedPage.Page)) { this.pnlPages.Controls.Add(associatedPage.Page); } // new way of notifying activation. Goal is to get rid of BackStageViewContentPanel // so plain old user controls can be added if (associatedPage.Page is IActivate) { ((IActivate)(associatedPage.Page)).Activate(); } try { var newButton = this.pnlMenu.Controls.OfType <BackstageViewButton>().Single(b => b.Tag == associatedPage); newButton.IsSelected = true; } catch (Exception ex) { log.Error(ex); } _activePage = associatedPage; }
public void DrawMenu(BackstageViewPage CurrentPage, bool force = false) { if (!force) { if (_activePage == CurrentPage || CurrentPage == null) { bool children = PageHasChildren(CurrentPage); if (!children) { return; } } } pnlMenu.Visible = false; pnlMenu.SuspendLayout(); pnlMenu.Controls.Clear(); // reset back to 0 ButtonTopPos = 0; foreach (BackstageViewPage page in _items) { if (page.GetType() == typeof(BackstageViewPage)) { // skip advanced pages if we are not advanced if (page.Advanced && !Advanced) { continue; } // its a base item. we want it if (((BackstageViewPage)page).Parent == null) { bool children = PageHasChildren(page); CreateLinkButton((BackstageViewPage)page, children); // remember whats expanded if (CurrentPage == page && children) { if (expanded.Contains((BackstageViewPage)page)) { expanded.Remove((BackstageViewPage)page); } else { expanded.Add((BackstageViewPage)page); } } // check for children foreach (BackstageViewPage childrenpage in _items) { if (childrenpage.GetType() == typeof(BackstageViewPage)) { if (((BackstageViewPage)childrenpage).Parent == ((BackstageViewPage)page)) { // check if current page has a parent thats not expanded if (CurrentPage == childrenpage && !expanded.Contains((BackstageViewPage)page)) { expanded.Add((BackstageViewPage)page); DrawMenu(CurrentPage, true); return; } // draw all the siblings if (expanded.Contains((BackstageViewPage)page) || this.DesignMode) { CreateLinkButton((BackstageViewPage)childrenpage, false, true); } } } } continue; } } else { ButtonTopPos += page.Spacing; } } pnlMenu.ResumeLayout(false); pnlMenu.PerformLayout(); pnlMenu.Visible = true; }