/// <summary>Draws the screen</summary> public void Render() { try { if (Console.WindowWidth < 80 || Console.WindowHeight < 25) { DialogBox.ShowDialogBox(WindowElements.Icon.IconType.EXCLAMATION, DialogBox.DialogBoxButtons.OK, "Unable to show STOP error. Window too small. Error Dialog Box to be shown instead."); DialogBox.ShowExceptionError(E); return; } //Minimum width is like 40x20 //30x15 + STOP RenderUtils.Color(ConsoleColor.Black, ConsoleColor.White); //Draw a box Draw.Box(ConsoleColor.Black, Console.WindowWidth, Console.WindowHeight - 4, 0, 2); //Draw the stop sign BasicGraphic StopSign = BasicGraphic.LoadFromResource(Properties.Resources.Stop); StopSign.Draw(1, 3); //Draw STOP! BasicFont.DefaultFont.DrawText("STOP", StopSign.GetWidth() + 2, 3, ConsoleColor.White); //Render Text Draw.Sprite("An unhandled exception has caused this program to crash.", ConsoleColor.Black, ConsoleColor.White, StopSign.GetWidth() + 2, 9); Draw.Sprite(E.Message, ConsoleColor.Black, ConsoleColor.White, 1, StopSign.GetHeight() + 3); //Render the Exception Stack Trace string StackTrace = E.StackTrace; if (Stripped) { StackTrace = DialogBox.StrippedStackTrace(E); } Draw.Sprite(FormattedText.Format(StackTrace, Console.WindowWidth - 1, Console.WindowHeight - 4 - StopSign.GetHeight() - 6).Replace("\n", "\n "), ConsoleColor.Black, ConsoleColor.White, 0, StopSign.GetHeight() + 5); //Draw writing. Draw.CenterText("Writing to disk", Console.WindowHeight - 4, ConsoleColor.Black, ConsoleColor.Red); File.AppendAllText("Errors.log", "\nERROR ON [" + DateTime.Now + "] " + E.Message + ": \n\n" + E.StackTrace); //Draw the last bit of text Draw.CenterText("Press a key to attempt to continue execution, or CTRL+C to close this program", Console.WindowHeight - 4, ConsoleColor.Black, ConsoleColor.Red); //Pause RenderUtils.Pause(); //Draw a box again to clear Draw.Box(ConsoleColor.Black, Console.WindowWidth, Console.WindowHeight - 4, 0, 2); } catch (Exception F) { DialogBox.ShowDialogBox(WindowElements.Icon.IconType.EXCLAMATION, DialogBox.DialogBoxButtons.OK, "There was an error rendering the error, the following exception is the original error"); DialogBox.ShowExceptionError(E); DialogBox.ShowDialogBox(WindowElements.Icon.IconType.EXCLAMATION, DialogBox.DialogBoxButtons.OK, "The following error occurred when rendering STOP"); DialogBox.ShowExceptionError(F); } }
/// <summary> /// Creates an Error Window that displays the specified text. <br></br><br></br> /// /// <b>NOTE!</b><br></br> /// ErrorWindow will only display the first three lines of text that it can fit. /// /// </summary> /// <param name="Text"></param> public ErrorWindow(string Text) : base(false, true, ConsoleColor.Gray, ConsoleColor.Red, ConsoleColor.White, "Error", 46, 8) { //First AllElements.Add(new Icon(this, Icon.IconType.ERROR, 1, 2)); //Add the Label AllElements.Add(new Label(this, FormattedText.Format(Text, 40, 3), ConsoleColor.Gray, ConsoleColor.Black, 5, 2)); CloseButton OK = new CloseButton(this, "[ O K ]", ConsoleColor.DarkGray, ConsoleColor.White, ConsoleColor.DarkBlue, Length - "[ O K ] ".Length, Height - 2); AllElements.Add(OK); HighlightedElement = OK; OK.Highlighted = true; }