Console.SetWindowSize() Method in C#
Last Updated :
06 Jun, 2022
Console.SetWindowSize(Int32, Int32) Method is used to change the height and width of the console window to the specified values.
Syntax: public static void SetWindowSize (int width, int height); Parameters: width: The width of the console window measured in columns. height: The height of the console window measured in rows.
Exceptions:
- ArgumentOutOfRangeException:
- If the width or height is less than or equal to zero
- width plus WindowLeft or height plus WindowTop is greater than or equal to MaxValue
- width or height is greater than the largest possible window width or height for the current screen resolution and console font.
- IOException: If an I/O error occurred.
Example 1: Getting the current dimensions of the window.
csharp
using System;
namespace GFG {
class Program {
static void Main( string [] args)
{
Console.WriteLine(Console.WindowWidth);
Console.WriteLine(Console.WindowHeight);
}
}
}
|
Output: Example 2: Setting the value of SetWindowSize
csharp
using System;
namespace GFG {
class Program {
static void Main( string [] args)
{
Console.SetWindowSize(40, 40);.
Console.WriteLine(Console.WindowWidth);
Console.WriteLine(Console.WindowHeight);
}
}
}
|
Output: Note: See the Horizontal Scroll Bar at the bottom of the Window in both the images. Reference:
Share your thoughts in the comments
Please Login to comment...