/// <summary> /// Creates a panel contains the warning message for accounts not in training. /// </summary> /// <param name="warningMessage"></param> /// <returns></returns> private static FlowLayoutPanel CreateAccountsNotTrainingPanel(string warningMessage) { // Create a flowlayout to hold the content FlowLayoutPanel warningPanel; FlowLayoutPanel tempWarningPanel = null; try { tempWarningPanel = new FlowLayoutPanel { AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Margin = new Padding(0, 0, 0, 2) }; // Add a picture on the left with a warning icon if (!Settings.UI.SafeForWork) { int portraitSize = Int32.Parse(Settings.UI.SystemTrayPopup.PortraitSize.ToString().Substring(1), CultureConstants.InvariantCulture); PictureBox tempPictureBoxWarning = null; try { tempPictureBoxWarning = new PictureBox(); tempPictureBoxWarning.Image = SystemIcons.Warning.ToBitmap(); tempPictureBoxWarning.SizeMode = PictureBoxSizeMode.StretchImage; tempPictureBoxWarning.Size = new Size(portraitSize, portraitSize); tempPictureBoxWarning.Margin = new Padding(2); PictureBox pbWarning = tempPictureBoxWarning; tempPictureBoxWarning = null; tempWarningPanel.Controls.Add(pbWarning); } finally { tempPictureBoxWarning?.Dispose(); } } // Adds a label to hold the message Label tempLabelMessage = null; try { tempLabelMessage = new Label { AutoSize = true, Text = warningMessage }; Label lblMessage = tempLabelMessage; tempLabelMessage = null; tempWarningPanel.Controls.Add(lblMessage); } finally { tempLabelMessage?.Dispose(); } tempWarningPanel.CreateControl(); warningPanel = tempWarningPanel; tempWarningPanel = null; } finally { tempWarningPanel?.Dispose(); } return warningPanel; }
/// <summary> /// Performs the custom layout. /// </summary> private void PerformCustomLayout() { // Remove controls and dispose them IEnumerable<Control> oldControls = MainFlowLayoutPanel.Controls.Cast<Control>().ToList(); MainFlowLayoutPanel.Controls.Clear(); foreach (Control ctl in oldControls) { ctl.Dispose(); } IEnumerable<Character> characters = GetCharacters; // Add controls for characters if (Settings.UI.SystemTrayPopup.GroupBy == TrayPopupGrouping.Account && Settings.UI.SystemTrayPopup.IndentGroupedAccounts) { List<APIKey> prevAPIKeys = new List<APIKey>(); foreach (Character character in characters) { OverviewItem charPanel = GetOverviewItem(character); List<APIKey> apiKeys = character.Identity.APIKeys.ToList(); if (!apiKeys.Exists(apiKey => prevAPIKeys.Contains(apiKey))) { MainFlowLayoutPanel.Controls.Add(charPanel); prevAPIKeys = apiKeys; } else { FlowLayoutPanel tempAccountGroupPanel = null; try { tempAccountGroupPanel = new FlowLayoutPanel(); tempAccountGroupPanel.Controls.Add(charPanel); tempAccountGroupPanel.AutoSize = true; tempAccountGroupPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; tempAccountGroupPanel.FlowDirection = FlowDirection.TopDown; tempAccountGroupPanel.Padding = new Padding(10, 0, 0, 0); tempAccountGroupPanel.CreateControl(); FlowLayoutPanel accountGroupPanel = tempAccountGroupPanel; tempAccountGroupPanel = null; MainFlowLayoutPanel.Controls.Add(accountGroupPanel); } finally { tempAccountGroupPanel?.Dispose(); } prevAPIKeys = apiKeys; } } } else MainFlowLayoutPanel.Controls.AddRange(characters.Select(GetOverviewItem).ToArray<Control>()); }