Csharp/CSharp Tutorial/Development/Console window settings

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

Change console title

<source lang="csharp">using System; public class MainClass {

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

}</source>

Change the Console Foreground and Background color

<source lang="csharp">using System; public class MainClass {

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

}</source>

Change the Console Foreground and Background color and clear

<source lang="csharp">using System; public class MainClass {

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

}</source>

Clear a Console

<source lang="csharp">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();
  }

}</source>

Reset console color, window size, buffer height and width

<source lang="csharp">using System; public class MainClass {

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

}</source>

Set cursor left, size, top and visible

<source lang="csharp">using System; public class MainClass {

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

}</source>