C#控制臺應用程序中輸出彩色字體
更新時間:2017年05月26日 10:05:43 作者:雲霏霏
這篇文章主要為大家詳細介紹了C#控制臺應用程序中輸出彩色字體的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C#控制臺輸出彩色字體的具體代碼,供大家參考,具體內容如下
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();
}
}
}
效果圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- C# 讀取ttf字體文件里的Unicode實現(xiàn)
- C# 獲取系統(tǒng)字體的示例代碼
- C#字體池技術實現(xiàn)代碼詳解
- C#使用RichTextBox實現(xiàn)替換文字及改變字體顏色功能示例
- C#使用private font改變PDF文件的字體詳解
- C#及WPF獲取本機所有字體和顏色的方法
- C#生成Code39條形碼而非條形碼字體的方法
- C# Winform使用擴展方法實現(xiàn)自定義富文本框(RichTextBox)字體顏色
- C#實現(xiàn)字體旋轉的方法
- C#實現(xiàn)縮放字體的方法
- C#讀取系統(tǒng)字體顏色與大小的方法
- windows系統(tǒng)下,如何在C#程序中自動安裝字體
相關文章
C#語法糖(Csharp Syntactic sugar)大匯總
首先需要聲明的是“語法糖”這個詞絕非貶義詞,它可以給我?guī)矸奖?,是一種便捷的寫法,編譯器會幫我們做轉換;而且可以提高開發(fā)編碼的效率,在性能上也不會帶來損失。這讓java開發(fā)人員羨慕不已,呵呵。2010-06-06
Winform ComboBox如何獨立繪制下拉選項的字體顏色
這篇文章主要介紹了Winform ComboBox如何獨立繪制下拉選項的字體顏色,幫助大家更好的理解和使用c# winform,感興趣的朋友可以了解下2020-11-11

