2013-02-26 89 views
15

我想在c#控制檯應用程序中設置控制檯窗口的大小。我得到一個ArgumentOutOfRangeException此消息:更改控制檯窗口的大小拋出ArgumentOutOfRangeException

值必須小於41在尺寸控制檯的當前最大窗口大小 。請注意,此值取決於屏幕 分辨率和控制檯字體。

我使用這個設置它:

Console.WindowHeight = 480; 

你如何正確設置控制檯窗口的大小?

+1

控制檯高度以行(線),而不是像素爲單位指定。 – 2013-02-26 21:24:59

+0

這是問題所在。如果您將其作爲答案發布,我會接受它。 – msbg 2013-02-26 21:27:18

+0

謝謝 - 張貼! – 2013-02-27 22:54:18

回答

33

Console.WindowHeight屬性的MSDN

行測量的控制檯窗口的高度。

正如你所看到的,這些不是像素。請記住,這些值可能會根據您的屏幕分辨率和控制檯字體而改變。你可以找到最大高度寬度值與Console.LargestWindowWidthConsole.LargestWindowHeight屬性。

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

剛注意到這個更詳細的答案。將其更改爲可接受的格式 – msbg 2014-03-27 22:02:27

-3

你可以設置一個windowHeight小於62,如果你試着超過這個值,拋出錯誤的系統。

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; } 

    The above information catch Console[from metadata]. 
+3

_U_可以使用_u'r_字體和顯示設置。我們其他人最好檢查'LargestWindowHeight'屬性。按照Habo的說法: – HABO 2013-02-26 21:48:07

+4

;這只是*你*的最大值。實際的最大值取決於每個人的屏幕尺寸。不只是程序員的屏幕尺寸/分辨率 - 而是最終用戶的。此外,你甚至不解釋*爲什麼*它必須小於62;在這種情況下,「62」是什麼意思? (*我*知道答案 - 但你的答案沒有說) – 2013-03-03 06:49:44