ex-*_*-vi 1 c# console-application
如何获得当前的控制台颜色(前景/背景)?
我有一种方法可以输出改变前景的单行:
public void ColorLine(string line, System.ConsoleColor foreground)
{
// maybe save original foreground color here
// then change it
System.Console.ForegroundColor = foreground;
// write line
System.Console.WriteLine(line);
// set original color
System.Console.ForegroundColor = // original foreground color;
}
Run Code Online (Sandbox Code Playgroud)
// save original foreground color here
ConsoleColor currentForeground = Console.ForegroundColor;
// set original color
Console.ForegroundColor = currentForeground
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
664 次 |
| 最近记录: |