Give some colors to my program ^_^

今天遇到一个关于color的程序,Console.BackgroundColor.Equals(ConsoleColor.Blue); 想想C#封装的接口其实蛮有意思的,轻轻一个点就能跳出那么相关的方法。

嘿嘿下面是我从MSDN里面找的程序,可以显示各种字体颜色还有背景色,敲出来纪念一下:

 

代码
   
   
1 class Example
2 {
3 public static void Main()
4 {
5 // Get a string array with the names of ConsoleColor enumeration members.
6   String[] colorNames = ConsoleColor.GetNames( typeof (ConsoleColor));
7
8 // Display each foreground color except black on a constant black background.
9   Console.WriteLine( " All the foreground colors (except Black) on a constant black background: " );
10
11 foreach ( string colorName in colorNames)
12 {
13 // Convert the string representing the enum name to the enum value.
14   ConsoleColor color = (ConsoleColor) Enum.Parse( typeof (ConsoleColor), colorName);
15
16 if (color == ConsoleColor.Black) continue ;
17
18 Console.Write( " {0,11}: " , colorName);
19 Console.BackgroundColor = ConsoleColor.Black;
20 Console.ForegroundColor = color;
21 Console.WriteLine( " This is foreground color {0}. " , colorName);
22 // Restore the original foreground and background colors.
23 Console.ResetColor();
24 }
25 Console.WriteLine();
26
27 // Display each background color except white with a constant white foreground.
28 Console.WriteLine( " All the background colors (except White) with a constant white background: " );
29
30 foreach ( string colorName in colorNames)
31 {
32 // Convert the string representing the enum name to the enum value.
33 ConsoleColor color = (ConsoleColor) Enum.Parse( typeof (ConsoleColor), colorName);
34
35 if (color == ConsoleColor.White) continue ;
36
37 Console.Write( " {0,11}: " , colorName);
38 Console.ForegroundColor = ConsoleColor.White;
39 Console.BackgroundColor = (ConsoleColor) Enum.Parse( typeof (ConsoleColor), colorName);
40 Console.WriteLine( " This is background color {0}. " , colorName);
41 Console.ResetColor();
42 }
43 }
44 }
45

 

 

Below is the output

Give some colors to my program ^_^_第1张图片

下面我想改造一下这个程序,具体怎么弄,还要稍等…

你可能感兴趣的:(color)