本文整理汇总了VB.NET中System.Console.ForegroundColor属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.ForegroundColor属性的具体用法?VB.NET Console.ForegroundColor怎么用?VB.NET Console.ForegroundColor使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Console
的用法示例。
在下文中一共展示了Console.ForegroundColor属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
If Console.BackgroundColor = ConsoleColor.Black Then
Console.BackgroundColor = ConsoleColor.Red
Console.ForegroundColor = ConsoleColor.Black
Console.Clear()
End If
End Sub
End Module
示例2: 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
输出:
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...
示例3: Module1
Module Module1
Sub Main()
Console.Title = "Custom Command Window"
Console.BackgroundColor = ConsoleColor.White
Console.ForegroundColor = ConsoleColor.DarkBlue
Console.WindowHeight = Console.LargestWindowHeight - 15
Console.WindowWidth = Console.LargestWindowWidth - 15
'Call a few methods to clear and pause the window.
Console.Clear()
End Sub
End Module