C# 控制台应用程序中输出彩色字体

简介: using System;class Example{ public static void Main() { // Get a string array with the names of ConsoleColor enumeration members.
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();
      }
   }
}
效果如下:

目录
相关文章
|
2月前
|
存储 运维 Serverless
Serverless 应用引擎产品使用之阿里函数计算中返回函数计算2.0控制台如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
|
2月前
|
C#
C# DEV 关于设置gridview 指定单元格字体为红色
C# DEV 关于设置gridview 指定单元格字体为红色
|
17天前
|
存储 安全 Java
程序与技术分享:C#值类型和引用类型的区别
程序与技术分享:C#值类型和引用类型的区别
16 0
|
2月前
|
C#
一个库帮你轻松的创建漂亮的.NET控制台应用程序
一个库帮你轻松的创建漂亮的.NET控制台应用程序
|
17天前
|
开发框架 .NET 编译器
程序与技术分享:C#基础知识梳理系列三:C#类成员:常量、字段、属性
程序与技术分享:C#基础知识梳理系列三:C#类成员:常量、字段、属性
10 2
|
28天前
|
C#
WPF/C#:程序关闭的三种模式
WPF/C#:程序关闭的三种模式
20 3
|
1月前
|
并行计算 算法 C#
C# Mandelbrot和Julia分形图像生成程序更新到2010-9-14版 支持多线程计算 多核处理器
此文档是一个关于分形图像生成器的介绍,作者分享了个人开发的M-J算法集成及色彩创新,包括源代码和历史版本。作者欢迎有兴趣的读者留言交流,并提供了邮箱(delacroix_xu@sina.com)以分享资源。文中还展示了程序的发展历程,如增加了真彩色效果、圈选放大、历史记录等功能,并分享了几幅精美的分形图像。此外,还提到了程序的新特性,如导入ini文件批量输出图像和更新一批图片的功能。文档末尾附有多张程序生成的高分辨率分形图像示例。
|
17天前
|
数据采集 XML 存储
技术经验分享:C#构造蜘蛛爬虫程序
技术经验分享:C#构造蜘蛛爬虫程序
|
17天前
|
安全 编译器 API
程序与技术分享:C#调用DLL的几种方法
程序与技术分享:C#调用DLL的几种方法
14 0
|
18天前
|
存储 IDE C#
C#入门:在JetBrains Rider中创建.Net Framework控制台应用程序,输出“Hello, World!”
C#入门:在JetBrains Rider中创建.Net Framework控制台应用程序,输出“Hello, World!”
49 0