private void CustomConsole_CloseClick(object sender, EventArgs e) { ConsoleViewControl console = sender as ConsoleViewControl; lock (_lockUI) { console.CloseClick -= new EventHandler(CustomConsole_CloseClick); CustomConsoleList.Remove(console); TabPage consolePage = console.Parent as TabPage; TabPage nextPage = null; TabPage prevTab = GetPreviousPage(consolePage); if (prevTab.Controls[0] is ConsoleViewControl) { nextPage = prevTab; } else { TabPage nextTab = GetNextPage(consolePage); if (null != nextTab) { nextPage = nextTab; } } TabControlMain.TabPages.Remove(consolePage); if (null != nextPage) { TabControlMain.SelectedTab = nextPage; } } }
/// <summary> /// Creates a new console tabpage and display console message. Called in invoke/locked state from ShowConsoleMessage /// </summary> /// <param name="notifyTime"></param> /// <param name="appDomainFriendlyName"></param> /// <param name="name"></param> /// <param name="message"></param> private string AddNewConsoleAndShowMessage(string notifyTime, string consoleName, string machineName, string appDomainFriendlyName, string parentEntryID, string message, bool showTime, bool showMachine, bool showAppDomain) { if (TabControlMain.TabPages.Count > 32) { return(null); } string validatedName = consoleName.Length > 32 ? consoleName.Substring(0, 31) : consoleName; ConsoleViewControl newConsole = new ConsoleViewControl(this, consoleName); newConsole.ShowCloseButton = true; TabPage newConsolePage = new TabPage("*" + validatedName); TabControlMain.TabPages.Add(newConsolePage); newConsolePage.ImageIndex = 0; newConsolePage.Controls.Add(newConsole); newConsole.Dock = DockStyle.Fill; CustomConsoleList.Add(newConsole); string newEntryID = newConsole.AddNewMessage(notifyTime, consoleName, machineName, appDomainFriendlyName, parentEntryID, message, showTime, showMachine, showAppDomain); newConsole.CloseClick += new EventHandler(CustomConsole_CloseClick); return(newEntryID); }