C# Console WindowWidth

Description

Console WindowWidth gets or sets the width of the console window.

Syntax

Console.WindowWidth has the following syntax.


public static int WindowWidth { get; set; }

Example


using System;//w w  w. j a v a 2  s. c  o  m

class Sample 
{
    public static void Main() 
    {
        int origWidth, width;  
        int origHeight, height;
    
        origWidth  = Console.WindowWidth;
        origHeight = Console.WindowHeight;
        Console.WriteLine(Console.WindowWidth);
        Console.WriteLine(Console.WindowHeight);
        Console.WriteLine("Press a key to continue");
        Console.ReadKey(true); 
    
        width  = origWidth/2;
        height = origHeight/2;
        Console.SetWindowSize(width, height);
        Console.WriteLine(Console.WindowWidth);
        Console.WriteLine(Console.WindowHeight);
        
        Console.ReadKey(true); 
    
        Console.SetWindowSize(origWidth, origHeight);
        Console.WriteLine(Console.WindowWidth);
        Console.WriteLine(Console.WindowHeight);

    }
}




















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version