Vb.net 如何在按键事件中使退格正常工作?

Vb.net 如何在按键事件中使退格正常工作?,vb.net,backspace,Vb.net,Backspace,我的代码在按键事件中,当我点击Backspace按钮时,它会显示一些特殊字符(如squre框)。如何防止出现这种情况,并使退格正常工作?请帮忙 Private Sub tmrKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrKeys.Tick Dim result As Integer Dim key As String = Nothing Dim i As I

我的代码在按键事件中,当我点击Backspace按钮时,它会显示一些特殊字符(如squre框)。如何防止出现这种情况,并使退格正常工作?请帮忙

Private Sub tmrKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrKeys.Tick
    Dim result As Integer
    Dim key As String = Nothing
    Dim i As Integer


    Try
        For i = 2 To 90
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                key = Chr(i)
                If i = 13 Then key = vbNewLine
                Exit For
            End If
        Next i

        If key <> Nothing Then
            If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
                txtlogs.Text &= key.ToUpper
            Else
                txtlogs.Text &= key.ToLower
            End If

        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try


End Sub
Private Sub tmrKeys_Tick(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理tmrKeys.Tick
将结果设置为整数
调暗键为字符串=无
作为整数的Dim i
尝试
对于i=2到90
结果=0
结果=GetAsyncKeyState(i)
如果结果=-32767,则
key=Chr(i)
如果i=13,则key=vbNewLine
退出
如果结束
接下来我
如果没有,那么
如果My.Computer.Keyboard.ShiftKeyDown或lse My.Computer.Keyboard.CapsLock,则
txtlogs.Text&=key.ToUpper
其他的
txtlogs.Text&=key.ToLower
如果结束
如果结束
特例
MsgBox(例如消息)
结束尝试
端接头

我有点想知道,除了系统范围的键盘记录器之外,这段代码还有什么用途。无论如何,为了回答您的问题,这会起到一定的作用,但不是万无一失的(比如它无法检测选定的文本并将其删除)

如果没有键,则
如果My.Computer.Keyboard.ShiftKeyDown或lse My.Computer.Keyboard.CapsLock,则
txtlogs.Text&=key.ToUpper
ElseIf key=vbBack然后
如果txtlogs.TextLength>0,则
Text=txtlogs.Text.Remove(txtlogs.TextLength-1)
如果结束
其他的
txtlogs.Text&=key.ToLower
如果结束
如果结束
    If key <> Nothing Then
        If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
            txtlogs.Text &= key.ToUpper
        ElseIf key = vbBack Then
            If txtlogs.TextLength > 0 Then
                txtlogs.Text = txtlogs.Text.Remove(txtlogs.TextLength - 1)
            End If
        Else
            txtlogs.Text &= key.ToLower
        End If
    End If