Home | Contact Us

CSharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript

C# Console.WindowHeight

This C# program uses the Console.WindowHeight property. It gets the LargestWindowHeight.

Console.WindowHeight changes the height of Console windows.

This can make certain Console programs much easier to use, particularly if they have a lot of output. We test the Console.WindowHeight property.

Minimum and maximum values for WindowHeight
    Maximum height may be different on your system.

Minimum height = 1
Maximum height = 83

Example. You can change the height of the Console window by assigning to the WindowHeight property. The hard part is choosing a value. You can find the largest available height with the LargestWindowHeight property. The minimum height is 1.

C# program that tests Console.WindowHeight

using System;
using System.Threading;

class Program
    static void Main()
	for (int i = 1; i <= Console.LargestWindowHeight; i++)
	    Console.WriteLine("Height = {0}", i);
	    Console.WindowHeight = i;


Height = 83
Press any key to continue...

This program shows possible console heights. On the present system, it goes from the minimum height of 1 to the maximum height of 83 rows. Depending on your screen resolution, you may have a different maximum number of rows.

Discussion. What are some ideas for finding the best window height? Unfortunately, if you set the WindowHeight to LargestWindowHeight, this will cause the window to go off the screen unless it is at the very top.

Therefore: It might be better to use a size that is a few rows smaller than LargestWindowHeight. Try subtracting 20 from it.

Summary. Console programs can be made more usable. One way you can do this is by adjusting the height of the window to make more text readable, as with the Console.WindowHeight and Console.LargestWindowHeight properties.