本文整理汇总了VB.NET中System.ConsoleKeyInfo.KeyChar属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ConsoleKeyInfo.KeyChar属性的具体用法?VB.NET ConsoleKeyInfo.KeyChar怎么用?VB.NET ConsoleKeyInfo.KeyChar使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.ConsoleKeyInfo 的用法示例。
在下文中一共展示了ConsoleKeyInfo.KeyChar属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
' Configure console.
Console.BufferWidth = 80
Console.WindowWidth = Console.BufferWidth
Console.TreatControlCAsInput = True
Dim inputString As String = String.Empty
Dim keyInfo As ConsoleKeyInfo
Console.WriteLine("Enter a string. Press <Enter> or Esc to exit.")
Do
keyInfo = Console.ReadKey(True)
' Ignore if Alt or Ctrl is pressed.
If (keyInfo.Modifiers And ConsoleModifiers.Alt) = ConsoleModifiers.Alt _
Then Continue Do
If (keyInfo.Modifiers And ConsoleModifiers.Control) = ConsoleModifiers.Control _
Then Continue Do
' Ignore if KeyChar value is \u0000.
If keyInfo.KeyChar = ChrW(0) Then Continue Do
' Ignore tab, clear key.
If keyInfo.Key = ConsoleKey.Tab Then Continue Do
' Handle backspace.
If keyInfo.Key = ConsoleKey.Backspace Then
' Are there any characters to erase?
If inputString.Length >= 1 Then
' Determine where we are in the console buffer.
Dim cursorCol As Integer = Console.CursorLeft - 1
Dim oldLength As Integer = inputString.Length
Dim extraRows As Integer = oldLength \ 80
inputString = inputString.Substring(0, oldLength - 1)
Console.CursorLeft = 0
Console.CursorTop = Console.CursorTop - extraRows
Console.Write(inputString + New String(" "c, oldLength - inputString.Length))
Console.CursorLeft = cursorCol
End If
Continue Do
End If
' Handle Escape key.
If keyInfo.Key = ConsoleKey.Escape Then Exit Do
' Handle key by adding it to input string.
Console.Write(keyInfo.KeyChar)
inputString += keyInfo.KeyChar
Loop While keyInfo.Key <> ConsoleKey.Enter
Console.WriteLine("{0}{0}You entered:{0} {1}", vbCrLf, _
IIf(String.IsNullOrEmpty(inputString), "<nothing>", inputString))
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:49,代码来源:ConsoleKeyInfo.KeyChar
注:本文中的System.ConsoleKeyInfo.KeyChar属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论