How do I change the full background color of the console window in C#?
In C#, the console has properties that can be used to change the background color of the console, and the foreground (text) color of the console.
Console.BackgroundColor // the background color
Console.ForegroundColor // the foreground/text color
The issue is that background color applies only where text is written, not to free space.
Console.BackgroundColor = ConsoleColor.White; // background color is white
Console.ForegroundColor = ConsoleColor.Blue; // text color is blue
Now, with the above code, it does indeed turn the text blue, but it only turns the background of the text white, instead of the entire console window's background.
Here's an example of what I mean:
As you can see, the white background only displays behind the text, and does not change the color of the entire console window.
How do I change the color of the entire console window?
您需要在设置颜色后清除控制台窗口,但在写入文本之前...
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Green;
Console.Clear();
Console.WriteLine("Hello World");
Console.ReadLine();
The running console controls the colors. You're essentially only changing the output of your application's color properties.
It's simple for changing the overall background color: Click on the 'C:' icon Select Properties and choose the Colors tab.
Now if you're wanting to do this programmatically, you'll want to launch you're own window:
CMD /T:F[n color index]
Color Value
Black 0 Blue 1 Green 2 Aqua 3 Red 4 Purple 5 Greenish Yellow 6 Light Gray 7 Gray 8 Light Blue 9 Light Green A Light Aqua B Light Red C Light Purple D Light Yellow E Bright White F
Or if you're using PowerShell, refer to this TechNet article: http://technet.microsoft.com/en-us/library/ee156814.aspx
This will work for you put it after your first open brace
{
system("cls");
system("color f3");
}
You can change the colors by number up to 7 I think example f1,f2,f3,f4... .
链接地址: http://www.djcxy.com/p/15320.html上一篇: 如何在Ubuntu中着色Git控制台?
下一篇: 如何更改C#中控制台窗口的完整背景颜色?