Open E-School

Male
Friday, February 24, 1984

Changing Console Window's size using C# throws ArgumentOutOfRangeException

Category: Programming Date: Tuesday, March 24, 2015

When you will try to set the size of the console window using C#’s Console.WindowHeight and Console.WindowWidth properties you will get ArgumentOutOfRangeException as shown below

Changing Console Window's size using C# throws ArgumentOutOfRangeException

 
The reason for this exception while setting the Console.WindowHeight = 100 is that you are trying to set the height of the window more than the allowed height as per your current screen resolution. Before you can decide how much height and width you can set for your console window using C# you should use the Console.LargestWindowHeight and Console.LargestWindowWidth properties to check the maximum height and width which you can set for your console window. Look at the code below

using System;    namespace ConsoleApplication1  {      class Program      {          public static void Main(string[] args)          {              Console.WriteLine("Largest console window height allowed : " +Console.LargestWindowHeight);              Console.WriteLine("Largest console window width allowed : " + Console.LargestWindowWidth);          }      }  }

Output

Changing Console Window's size using C# throws ArgumentOutOfRangeException


Here you clearly see that the largest console window height which is allowed is 69. When you are setting it to 100 you will get the ArgumentOutOfRangeException because you are going out of range to set the console window height. The same rule applies to console window width settings also.

Rate this article and help us improve

Please Login to rate
Overall ratings: 0 | Rating: out of 5
Previous Article Next Article

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp