如何改变在C#控制台窗口的全部背景颜色? [英] How do I change the full background color of the console window in C#?

查看:752
本文介绍了如何改变在C#控制台窗口的全部背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,控制台有属性:

In C#, the console has properties:

Console.BackgroundColor // the background color
Console.ForegroundColor // the foreground/text color

这些可以用来更改控制台的背景色和,前景或文本,控制台的颜色

These can be used to change the background color of the console, and the foreground, or text, color of the console.

的问题是,当我这样做:

The issue is, when I do something like:

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 and the background white, but it only turns the background of the text white, instead of the entire background white.

下面是什么,我的意思是一个例子:
< IMG SRC =http://i.stack.imgur.com/LGC6i.pngALT =背景仅覆盖不是整个控制台窗口中的文字的背景,>

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.

那么,如何修改我的整个控制台窗口的颜色?

So, how do I change the color of the entire console window?

推荐答案

您需要清除控制台窗口后设置的颜色,但之前写的文字...

You need to clear the console window AFTER setting the colors but BEFORE you write the text...

Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Green;

Console.Clear();

Console.WriteLine("Hello World");

Console.ReadLine();

这篇关于如何改变在C#控制台窗口的全部背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆