C#控制臺(tái)應(yīng)用程序中輸出彩色字體
更新時(shí)間:2017年05月26日 10:05:43 作者:雲(yún)霏霏
這篇文章主要為大家詳細(xì)介紹了C#控制臺(tái)應(yīng)用程序中輸出彩色字體的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了C#控制臺(tái)輸出彩色字體的具體代碼,供大家參考,具體內(nèi)容如下
using System;
class Example
{
public static void Main()
{
// Get a string array with the names of ConsoleColor enumeration members.
String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));
// Display each foreground color except black on a constant black background.
Console.WriteLine("All the foreground colors (except Black) on a constant black background:");
foreach (string colorName in colorNames)
{
// Convert the string representing the enum name to the enum value.
ConsoleColor color = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName);
if (color == ConsoleColor.Black) continue;
Console.Write("{0,11}: ", colorName);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = color;
Console.WriteLine("This is foreground color {0}.", colorName);
// Restore the original foreground and background colors.
Console.ResetColor();
}
Console.WriteLine();
// Display each background color except white with a constant white foreground.
Console.WriteLine("All the background colors (except White) with a constant white foreground:");
foreach (string colorName in colorNames)
{
// Convert the string representing the enum name to the enum value.
ConsoleColor color = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName);
if (color == ConsoleColor.White) continue;
Console.Write("{0,11}: ", colorName);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName);
Console.WriteLine("This is background color {0}.", colorName);
Console.ResetColor();
}
}
}
效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- C# 讀取ttf字體文件里的Unicode實(shí)現(xiàn)
- C# 獲取系統(tǒng)字體的示例代碼
- C#字體池技術(shù)實(shí)現(xiàn)代碼詳解
- C#使用RichTextBox實(shí)現(xiàn)替換文字及改變字體顏色功能示例
- C#使用private font改變PDF文件的字體詳解
- C#及WPF獲取本機(jī)所有字體和顏色的方法
- C#生成Code39條形碼而非條形碼字體的方法
- C# Winform使用擴(kuò)展方法實(shí)現(xiàn)自定義富文本框(RichTextBox)字體顏色
- C#實(shí)現(xiàn)字體旋轉(zhuǎn)的方法
- C#實(shí)現(xiàn)縮放字體的方法
- C#讀取系統(tǒng)字體顏色與大小的方法
- windows系統(tǒng)下,如何在C#程序中自動(dòng)安裝字體
相關(guān)文章
Winform實(shí)現(xiàn)鼠標(biāo)可穿透的窗體鏤空效果
這篇文章主要介紹了Winform實(shí)現(xiàn)鼠標(biāo)可穿透的窗體鏤空效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
C# 實(shí)現(xiàn)ADSL自動(dòng)斷網(wǎng)和撥號(hào)的方法(適用于撥號(hào)用戶)
下面小編就為大家?guī)?lái)一篇C# 實(shí)現(xiàn)ADSL自動(dòng)斷網(wǎng)和撥號(hào)的方法(適用于撥號(hào)用戶)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
C#通過(guò)PInvoke調(diào)用c++函數(shù)的備忘錄的實(shí)例詳解
這篇文章主要介紹了C#通過(guò)PInvoke調(diào)用c++函數(shù)的備忘錄的實(shí)例以及相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2019-08-08
C#調(diào)用usb攝像頭的實(shí)現(xiàn)方法
這篇文章主要介紹了C#調(diào)用usb攝像頭的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

