更改控制台窗口的大小会抛出ArgumentOutOfRangeException

我试图在ac#console应用程序中设置控制台窗口的大小。 我收到带有此消息的ArgumentOutOfRangeException

该值必须小于该维度中控制台当前最大窗口大小41。 请注意,此值取决于屏幕分辨率和控制台字体。

我用它来设置它:

 Console.WindowHeight = 480; 

如何正确设置控制台窗口的大小?

Console.WindowHeight属性的MSDN

控制台窗口的高度按行测量。

如您所见,这些不是像素 。 请记住,这些值可能会根据您的屏幕分辨率和控制台字体而改变。 您可以使用Console.LargestWindowWidthConsole.LargestWindowHeight属性找到最大高度宽度值。

 Console.WriteLine(Console.LargestWindowHeight); Console.WriteLine(Console.LargestWindowWidth); 

控制台高度以行(行)指定,而不是像素。

http://msdn.microsoft.com/en-us/library/system.console.windowheight.aspx

你可以设置一个小于62的windowHeight,如果你尝试超过这个值错误抛出系统。

 class Pro { public static void fun() { Console.WindowHeight = 61; Console.WriteLine("Welcome to asp .net "); } static void Main(string[] args) { Pro.fun(); } // Summary: // Gets the largest possible number of console window rows, based on the current // font and screen resolution. // // Returns: // The height of the largest possible console window measured in rows. public static int LargestWindowHeight { get; } // Summary: // Gets the largest possible number of console window columns, based on the // current font and screen resolution. // // Returns: // The width of the largest possible console window measured in columns. public static int LargestWindowWidth { get; } 

以上信息捕获Console [来自元数据]。