当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET ConsoleColor枚举代码示例

本文整理汇总了VB.NET中System.ConsoleColor枚举的典型用法代码示例。如果您正苦于以下问题:VB.NET ConsoleColor枚举的具体用法?VB.NET ConsoleColor怎么用?VB.NET ConsoleColor使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。


在下文中一共展示了ConsoleColor枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Public Module Example
   Public Sub Main()
      ' Get an array with the values of ConsoleColor enumeration members.
      Dim colors() As ConsoleColor = ConsoleColor.GetValues(GetType(ConsoleColor))
      ' Save the current background and foreground colors.
      Dim currentBackground As ConsoleColor = Console.BackgroundColor
      Dim currentForeground As ConsoleColor = Console.ForegroundColor
      
      ' Display all foreground colors except the one that matches the background.
      Console.WriteLine("All the foreground colors except {0}, the background color:",
                        currentBackground)
      For Each color In colors
         If color = currentBackground Then Continue For
          
         Console.ForegroundColor = color
         Console.WriteLine("   The foreground color is {0}.", color)
      Next 
      Console.WriteLine()
      
      ' Restore the foreground color.
      Console.ForegroundColor = currentForeground
      
      ' Display each background color except the one that matches the current foreground color.
      Console.WriteLine("All the background colors except {0}, the foreground color:",
                        currentForeground)
      For Each color In colors
         If color = currentForeground  then Continue For
         Console.BackgroundColor = color
         Console.WriteLine("   The background color is {0}.", color)
      Next
      ' Restore the original console colors.
      Console.ResetColor
      Console.WriteLine()
      Console.WriteLine("Original colors restored...")
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:36,代码来源:ConsoleColor

输出:

The background color is DarkCyan.
The background color is DarkRed.
The background color is DarkMagenta.
The background color is DarkYellow.
The background color is Gray.
The background color is DarkGray.
The background color is Blue.
The background color is Green.
The background color is Cyan.
The background color is Red.
The background color is Magenta.
The background color is Yellow.

Original colors restored...


注:本文中的System.ConsoleColor枚举示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。