本文整理匯總了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