private static int UpdateConsoleSize(int width, int height) { s_virtualWin = new Integration.CharInfo[width * height]; s_rect = new Integration.SmallRect() { Left = 0, Top = 0, Right = Convert.ToInt16(width), Bottom = Convert.ToInt16(height) }; Console.CursorVisible = false; s_width = width; s_height = height; return(SetConsoleDimension(width, height)); }
/** * <summary> * Instantiate conhics, this will * apply correct console and * character dimensions, start * event handler (optional) and * finally apply a title to the console. * </summary> */ public static void Setup(string title = "", int columns = 120, int rows = 30, short charWidth = 8, short charHeight = 16, bool activeEventCapture = true) { s_activeEventCapture = activeEventCapture; if (title.Length > 0) { Console.Title = title; } // Calculate how much larger/smaller the characters are than default int charWidthPercentage = 8 / charWidth; int charHeightPercentage = 16 / charHeight; if (Console.LargestWindowWidth * charWidthPercentage < columns || Console.LargestWindowHeight * charHeightPercentage < rows) { throw new Exception("Requested window size exceeds the screen capacity"); } SetupFontSize(charWidth, charHeight); SetConsoleDimension(columns, rows); Console.SetWindowPosition(0, 0); Console.CursorVisible = false; s_width = Console.WindowWidth; s_height = Console.WindowHeight; s_handle = Integration.CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (s_handle.IsInvalid) { throw new Exception("Could not start..."); } s_virtualWin = new Integration.CharInfo[s_width * s_height]; s_rect = new Integration.SmallRect() { Left = 0, Top = 0, Right = Convert.ToInt16(s_width), Bottom = Convert.ToInt16(s_height) }; // Start event handler Keyboard.IsEnabled = activeEventCapture; Mouse.IsEnabled = activeEventCapture; Clear(); }