protected override void Dispose(bool disposing) { if (disposing && createNewLink != null) { createNewLink.Dispose(); createNewLink = null; } base.Dispose(disposing); }
/// <summary> /// Updates the content. /// </summary> private void UpdateContent() { // When no certificate class is selected, we just hide the right panel. if (m_selectedCertificate == null) { // View help message lblHelp.Visible = true; panelRight.Visible = false; return; } // Hide help message lblHelp.Visible = false; // Updates controls visibility panelRight.Visible = true; lblName.Text = m_selectedCertificate.Name; lblCategory.Text = m_selectedCertificate.Category.Name; textboxDescription.Text = m_selectedCertificate.Certificate.Description; // Training time per certificate level for (int i = 1; i <= 5; i++) { UpdateLevelLabel(panelHeader.Controls.OfType <Label>() .First(label => label.Name == $"lblLevel{i}Time"), i); } // Only read the recommendations from one level, because they are all the same PersistentSplitContainer rSplCont = rightSplitContainer; List <Control> newItems = new List <Control>(); SortedList <string, Item> ships = new SortedList <string, Item>(); foreach (Item ship in m_selectedCertificate.Certificate.Recommendations) { ships.Add(ship.Name, ship); } Label tempLabel = null; try { tempLabel = new Label(); tempLabel.Font = new Font(tempLabel.Font, FontStyle.Bold); tempLabel.AutoSize = true; tempLabel.Dock = DockStyle.Top; tempLabel.Text = @"Recommended For"; tempLabel.Padding = new Padding(5); Label tsl = tempLabel; tempLabel = null; newItems.Add(tsl); Size tslTextSize = TextRenderer.MeasureText(tsl.Text, Font); int panelMinSize = rSplCont.Panel2MinSize; rSplCont.Panel2MinSize = panelMinSize > tslTextSize.Width + HPad ? panelMinSize : tslTextSize.Width + HPad; rSplCont.SplitterDistance = rSplCont.Width - rSplCont.Panel2MinSize; } finally { tempLabel?.Dispose(); } foreach (LinkLabel linkLabel in ships.Values .Select(ship => { LinkLabel linkLabel; LinkLabel tempLinkLabel = null; try { tempLinkLabel = new LinkLabel(); tempLinkLabel.LinkBehavior = LinkBehavior.HoverUnderline; tempLinkLabel.Padding = new Padding(16, 0, 0, 0); tempLinkLabel.Dock = DockStyle.Top; tempLinkLabel.Text = ship.Name; tempLinkLabel.Tag = ship; linkLabel = tempLinkLabel; tempLinkLabel = null; } finally { tempLinkLabel?.Dispose(); } return(linkLabel); })) { linkLabel.MouseClick += recommendations_MenuItem; newItems.Add(linkLabel); } // Updates the recommendations for this certificate UpdateRecommendations(newItems, rSplCont); // Update the menus and such UpdateEligibility(); // Update the certificates tree display certDisplayControl.CertificateClass = m_selectedCertificate; }
/// <summary> /// Populates the links. /// </summary> private void populateLinks() { if (pagesCount < currentPage || pagesCount == 0 || currentPage == 0) { // info hasn't been entered completely yet return; } // set label's text labelPage.Text = "Page " + currentPage.ToString() + " of " + pagesCount.ToString() + "."; // set position of the two first (static) links linkLabelFirst.Location = new Point( labelPage.Location.X + labelPage.Width + gap, labelPage.Location.Y); linkLabelPrev.Location = new Point( linkLabelFirst.Location.X + linkLabelFirst.Width + gap, linkLabelFirst.Location.Y); // calculate number of links on both left and right sides // of the current page uint pagesLeft = numPagesShown; uint pagesRight = numPagesShown; uint pagesShownTotal = (uint)Math.Min(2 * numPagesShown + 1, pagesCount); if (currentPage <= numPagesShown) { pagesLeft = currentPage - 1; pagesRight = pagesShownTotal - pagesLeft - 1; } else if (pagesCount - currentPage <= numPagesShown) { pagesRight = pagesCount - currentPage; pagesLeft = pagesShownTotal - pagesRight - 1; } // change existing pages without deleting them // to avoid blinking for (int i = 0; i < Math.Min(pagesShownTotal, pages.Count); i++) { uint pageNum = (uint)(currentPage - pagesLeft + i); LinkLabel page = (LinkLabel)pages[i]; page.Tag = pageNum; page.Text = page.Tag.ToString(); page.Font = pageNum == currentPage ? new Font(this.Font, FontStyle.Bold) : null; // set page link's location relative to the previous // link LinkLabel pagePrev = i > 0 ? (LinkLabel)pages[i - 1] : linkLabelPrev; page.Location = new Point( pagePrev.Location.X + pagePrev.Width + gap, pagePrev.Location.Y); } if (pages.Count > pagesShownTotal) { // remove unnecessary pages for (int i = pages.Count - 1; i >= pagesShownTotal; i--) { LinkLabel page = (LinkLabel)pages[i]; page.Parent = null; page.Visible = false; pages.RemoveAt(i); page.Dispose(); } } else if (pages.Count < pagesShownTotal) { // add pages for (int i = pages.Count; i < pagesShownTotal; i++) { LinkLabel page = new LinkLabel(); page.AutoSize = true; page.Tag = (uint)(currentPage - pagesLeft + i); page.Text = page.Tag.ToString(); page.Height = linkLabelFirst.Height; // set page location relative to the previous page LinkLabel pagePrev = pages.Count > 0 ? (LinkLabel)pages[i - 1] : linkLabelPrev; page.Font = i == currentPage ? new Font(this.Font, FontStyle.Bold) : null; page.Parent = this; page.Location = new Point( pagePrev.Location.X + pagePrev.Width + gap, pagePrev.Location.Y); pages.Add(page); page.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler( linkClicked); } } Debug.Assert(pages.Count > 0); // change location of the last two links (next & last) LinkLabel pageLast = (LinkLabel)pages[pages.Count - 1]; linkLabelNext.Location = new Point( pageLast.Location.X + pageLast.Width + gap, linkLabelNext.Location.Y); linkLabelLast.Location = new Point( linkLabelNext.Location.X + linkLabelNext.Width, linkLabelLast.Location.Y); checkPages(); }