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#实现图像反色的方法

    C#实现图像反色的方法

    这篇文章主要介绍了C#实现图像反色的方法,涉及C#操作图像颜色转换的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-04-04
  • C#交错数组用法实例

    C#交错数组用法实例

    这篇文章主要介绍了C#交错数组用法,较为详细的分析了交错数组的概念、用法并实例分析了交错数组的使用技巧,需要的朋友可以参考下
    2015-04-04
  • C#中匿名方法与委托的关系介绍

    C#中匿名方法与委托的关系介绍

    这篇文章介绍了C#中匿名方法与委托的关系,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-08-08
  • Winform实现鼠标可穿透的窗体镂空效果

    Winform实现鼠标可穿透的窗体镂空效果

    这篇文章主要介绍了Winform实现鼠标可穿透的窗体镂空效果的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2016-10-10
  • C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)

    C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)

    下面小编就为大家带来一篇C# 实现ADSL自动断网和拨号的方法(适用于拨号用户)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-12-12
  • C#实现更改MDI窗体背景颜色的方法

    C#实现更改MDI窗体背景颜色的方法

    这篇文章主要介绍了C#实现更改MDI窗体背景颜色的方法,涉及C#窗体背景色的设置技巧,非常简单实用,需要的朋友可以参考下
    2015-08-08
  • C#通过PInvoke调用c++函数的备忘录的实例详解

    C#通过PInvoke调用c++函数的备忘录的实例详解

    这篇文章主要介绍了C#通过PInvoke调用c++函数的备忘录的实例以及相关知识点内容,有兴趣的朋友们学习下。
    2019-08-08
  • C#调用usb摄像头的实现方法

    C#调用usb摄像头的实现方法

    这篇文章主要介绍了C#调用usb摄像头的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • 详细解析C#多线程同步事件及等待句柄

    详细解析C#多线程同步事件及等待句柄

    本篇文章主要介绍了C#多线程同步事件及等待句柄,希望通过本篇的介绍能对常见的线程同步方法有一个整体的认识,有需要的可以了解一下。
    2016-11-11
  • 分享用于操作FTP的客户端C#类

    分享用于操作FTP的客户端C#类

    用.net自带的FtpWebRequest做的ftp客户端得程序,有一个功能实现起来会非常苦难,就是移动文件和文件夹的功能。所以后来又找了一个类,用socket实现的,发现比用ftpWebRequest功能要强。基本的ftp客户端得命令都实现了。
    2015-05-05

最新评论