本文整理汇总了VB.NET中System.Console.Clear方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.Clear方法的具体用法?VB.NET Console.Clear怎么用?VB.NET Console.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Console
的用法示例。
在下文中一共展示了Console.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
' Save colors so they can be restored when use finishes input.
Dim dftForeColor As ConsoleColor = Console.ForegroundColor
Dim dftBackColor As ConsoleColor = Console.BackgroundColor
Dim continueFlag As Boolean = True
Console.Clear()
Do
Dim newForeColor As ConsoleColor
Dim newBackColor As ConsoleColor
Dim foreColorSelection As Char = GetKeyPress("Select Text Color (B for Blue, R for Red, Y for Yellow): ",
{ "B"c, "R"c, "Y"c } )
Select Case foreColorSelection
Case "B"c, "b"c
newForeColor = ConsoleColor.DarkBlue
Case "R"c, "r"c
newForeColor = ConsoleColor.DarkRed
Case "Y"c, "y"c
newForeColor = ConsoleColor.DarkYellow
End Select
Dim backColorSelection As Char = GetKeyPress("Select Background Color (W for White, G for Green, M for Magenta): ",
{ "W"c, "G"c, "M"c })
Select Case backColorSelection
Case "W"c, "w"c
newBackColor = ConsoleColor.White
Case "G"c, "g"c
newBackColor = ConsoleColor.Green
Case "M"c, "m"c
newBackColor = ConsoleColor.Magenta
End Select
Console.WriteLine()
Console.Write("Enter a message to display: ")
Dim textToDisplay As String = Console.ReadLine()
Console.WriteLine()
Console.ForegroundColor = newForeColor
Console.BackgroundColor = newBackColor
Console.WriteLine(textToDisplay)
Console.WriteLine()
If Char.ToUpper(GetKeyPress("Display another message (Y/N): ", { "Y"c, "N"c } )) = "N" Then
continueFlag = False
End If
' Restore the default settings and clear the screen.
Console.ForegroundColor = dftForeColor
Console.BackgroundColor = dftBackColor
Console.Clear()
Loop While continueFlag
End Sub
Private Function GetKeyPress(msg As String, validChars() As Char) As Char
Dim keyPressed As ConsoleKeyInfo
Dim valid As Boolean = False
Console.WriteLine()
Do
Console.Write(msg)
keyPressed = Console.ReadKey()
Console.WriteLine()
If Array.Exists(validChars, Function(ch As Char) ch.Equals(Char.ToUpper(keypressed.KeyChar)))
valid = True
End If
Loop While Not valid
Return keyPressed.KeyChar
End Function
End Module
示例2: Sample
' This example demonstrates the
' Console.CursorLeft and
' Console.CursorTop properties, and the
' Console.SetCursorPosition and
' Console.Clear methods.
Class Sample
Protected Shared origRow As Integer
Protected Shared origCol As Integer
Protected Shared Sub WriteAt(s As String, x As Integer, y As Integer)
Try
Console.SetCursorPosition(origCol + x, origRow + y)
Console.Write(s)
Catch e As ArgumentOutOfRangeException
Console.Clear()
Console.WriteLine(e.Message)
End Try
End Sub
Public Shared Sub Main()
' Clear the screen, then save the top and left coordinates.
Console.Clear()
origRow = Console.CursorTop
origCol = Console.CursorLeft
' Draw the left side of a 5x5 rectangle, from top to bottom.
WriteAt("+", 0, 0)
WriteAt("|", 0, 1)
WriteAt("|", 0, 2)
WriteAt("|", 0, 3)
WriteAt("+", 0, 4)
' Draw the bottom side, from left to right.
WriteAt("-", 1, 4) ' shortcut: WriteAt("---", 1, 4)
WriteAt("-", 2, 4) ' ...
WriteAt("-", 3, 4) ' ...
WriteAt("+", 4, 4)
' Draw the right side, from bottom to top.
WriteAt("|", 4, 3)
WriteAt("|", 4, 2)
WriteAt("|", 4, 1)
WriteAt("+", 4, 0)
' Draw the top side, from right to left.
WriteAt("-", 3, 0) ' shortcut: WriteAt("---", 1, 0)
WriteAt("-", 2, 0) ' ...
WriteAt("-", 1, 0) ' ...
'
WriteAt("All done!", 0, 6)
Console.WriteLine()
End Sub
End Class
输出:
+---+ | | | | | | +---+ All done!
示例3: Console.Clear()
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