2013-02-09 134 views
7

我搜索了Web,但似乎找不到解決方案。我希望整個控制檯應用程序窗口都是特定的顏色,例如藍色。我怎麼做?更改C#控制檯應用程序的背景顏色

+1

你是如何搜索? [Console.BackgroundColor屬性](http://msdn.microsoft.com/en-us/library/system.console.backgroundcolor.aspx) – 2013-02-09 22:01:04

+1

您正在尋找一種方法來使整個黑色背景具有特定的顏色,或者你正在尋找Soner(帶截圖)的答案嗎? – bas 2013-02-09 22:10:44

+0

在您的嘗試中,您可能忘記添加Console.Clear();線後設置顏色Console.BackgroundColor – 2014-05-21 16:42:08

回答

3

OP的問題是要求如何將整個背景顏色設置爲藍色。沒有其他樣品正確顯示。具體方法如下:

namespace ClearConsole 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.BackgroundColor = ConsoleColor.Blue; 
      Console.Clear(); 

     } 
    } 
} 
5

可以Console.BackgroundColor屬性設置爲ConsoleColor枚舉..

獲取或設置控制檯的背景色。要整體更改>控制檯窗口的背景顏色,請設置BackgroundColor屬性並調用Clear方法。

Console.BackgroundColor = ConsoleColor.Blue; 
Console.Clear(); 

enter image description here

你也可以使用Console.ForegroundColor屬性

獲取或設置控制檯的前景色。

Console.ForegroundColor = ConsoleColor.Blue; 

enter image description here

+3

@SonerGönül第一屏幕截圖。在屏幕截圖之前有一個'console.clear();'命令。所以整個背景應該是藍色的。 – 2014-05-26 17:57:42

27

簡單地設置背景顏色,並呼籲Console.Clear()

class Program { 
    static void Main(string[] args) { 
     Console.BackgroundColor = ConsoleColor.Blue; 
     Console.Clear(); 
     Console.ForegroundColor = ConsoleColor.White; 
     Console.Write("Press any key to continue"); 
     Console.ReadKey(); 
    } 
} 

enter image description here

1
Console.ForegroundColor = Color.Blue; 

Console.WriteLine("This string is blue!");