Change Console window properties

Change the WindowLeft, WindowTop, WindowHeight, and WindowWidth.

You can also change the BackgroundColor and ForegroundColor properties.

You can manipulate the cursor with the CursorLeft, CursorTop, and CursorSize properties:


using System;


class Sample
{
    public static void Main()
    {
        Console.WindowWidth = Console.LargestWindowWidth;
        Console.ForegroundColor = ConsoleColor.Green;
        Console.Write("asdf... 123%");
        Console.CursorLeft = 3;
        Console.Write("1111");
    }
}

Properties to Control the Appearance of the Console:

The following example uses the properties and methods of the Console class to change the appearance of the Windows console:


using System;

public class MainClass
{
    static void Main(string[] args)
    {
        // Display the standard console. 
        Console.Title = "Standard Console";
        Console.WriteLine("Press Enter to change the console's appearance.");
        Console.ReadLine();
        // Change the console appearance and redisplay. 
        Console.Title = "Resized Console";
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.BackgroundColor = ConsoleColor.Yellow;

        //Console.ResetColor(); 
        Console.Clear();
        Console.SetWindowSize(100, 50);
        Console.BufferHeight = 500;
        Console.BufferWidth = 100;
        Console.CursorLeft = 20;
        Console.CursorSize = 50;
        Console.CursorTop = 20;
        Console.CursorVisible = false;
        Console.WriteLine("Main method complete. Press Enter.");
        Console.ReadLine();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.