public static void SetBufferSize(int width, int height)
{
// Ensure the new size is not smaller than the console window
Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO csbi = GetBufferInfo();
Interop.Kernel32.SMALL_RECT srWindow = csbi.srWindow;
if (width < srWindow.Right + 1 || width >= short.MaxValue)
throw new ArgumentOutOfRangeException(nameof(width), width, SR.ArgumentOutOfRange_ConsoleBufferLessThanWindowSize);
if (height < srWindow.Bottom + 1 || height >= short.MaxValue)
throw new ArgumentOutOfRangeException(nameof(height), height, SR.ArgumentOutOfRange_ConsoleBufferLessThanWindowSize);
Interop.Kernel32.COORD size = new Interop.Kernel32.COORD();
size.X = (short)width;
size.Y = (short)height;
if (!Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, size))
{
throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error());
}
}