>  기사  >  백엔드 개발  >  C# 콘솔 응용 프로그램에서 컬러 글꼴을 출력하는 방법에 대한 자세한 소개

C# 콘솔 응용 프로그램에서 컬러 글꼴을 출력하는 방법에 대한 자세한 소개

黄舟
黄舟원래의
2017-05-28 10:01:242589검색

이 글은 주로 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# 콘솔 응용 프로그램에서 컬러 글꼴을 출력하는 방법에 대한 자세한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.