Csharp/CSharp Tutorial/Development/Console window settings

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Change console title

using System;
public class MainClass
{
    static void Main(string[] args)
    {
        // Display the standard Console.
        Console.Title = "Standard Console";
    }
}

Change the Console Foreground and Background color

using System;
public class MainClass
{
    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.BackgroundColor = ConsoleColor.Green;
    }
}

Change the Console Foreground and Background color and clear

using System;
public class MainClass
{
    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.BackgroundColor = ConsoleColor.Green;
        //Console.Clear();
    }
}

Clear a Console

using System;
public class MainClass
{
    static void Main(string[] args) {
       // Change the console appearance and redisplay.
       Console.Title = "Cleared / Colored Console";
       Console.ForegroundColor = ConsoleColor.Blue;
       Console.BackgroundColor = ConsoleColor.Yellow;
       Console.Clear();
   }
}

Reset console color, window size, buffer height and width

using System;
public class MainClass
{
    static void Main(string[] args)
    {
        Console.ResetColor();
        Console.SetWindowSize(100, 50);
        Console.BufferHeight = 500;
        Console.BufferWidth = 100;
    }
}

Set cursor left, size, top and visible

using System;
public class MainClass
{
    static void Main(string[] args)
    {
        Console.CursorLeft = 20;
        Console.CursorSize = 50;
        Console.CursorTop = 20;
        Console.CursorVisible = false;
    }
}