msbg
msbg

Reputation: 4962

Changing Console Window's size throws ArgumentOutOfRangeException

I am trying to set the size of the Console Window in a c# console application. I get an ArgumentOutOfRangeException with this message:

The value must be less than the console's current maximum window size of 41 in that dimension. Note that this value depends on screen resolution and the console font.

I am using this to set it:

Console.WindowHeight = 480;

How do you set the Console window's size properly?

Upvotes: 24

Views: 41870

Answers (4)

John Zabroski
John Zabroski

Reputation: 2357

Microsoft recently published some information around this, see:

  1. Understanding Windows Console Host Settings

Try this in powershell:

$windowSize = $(get-item hkcu:\console).GetValue("WindowSize")
$windowHeight = $windowSize -shr 16
$windowWidth = ($windowSize -shl 16) -shr 16

Upvotes: 0

DOT.NET
DOT.NET

Reputation: 101

you can set a windowHeight less than 62, if u try exceed this value error throw the system.

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].

Upvotes: -4

Soner Gönül
Soner Gönül

Reputation: 98750

From MSDN of Console.WindowHeight property:

The height of the console window measured in rows.

As you can see, these are not pixels. Just remember, these values can change depending on your screen resolution and the console font. You can find maximum height and width values with Console.LargestWindowWidth and Console.LargestWindowHeight properties.

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

Upvotes: 50

David Pfeffer
David Pfeffer

Reputation: 39833

Console height is specified in rows (lines), not pixels.

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

Upvotes: 1

Related Questions