gpt4 book ai didi

vb.net - 文本框不允许按退格键?

转载 作者:行者123 更新时间:2023-12-02 02:21:14 24 4
gpt4 key购买 nike

我制作了一个文本框,将字符的使用仅限于数字和句点。很好,但现在我无法输入退格键来修改在文本框中键入的任何数据。我该如何解决这个问题?

    Private Sub TextBox10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox10.KeyPress

Dim allowedChars As String = "1234567890."

If allowedChars.IndexOf(e.KeyChar) = -1 Then
' Invalid Character
e.Handled = True
End If

End Sub

最佳答案

您可以使用测试退格键

If e.KeyChar = ChrW(8) Then
MessageBox.Show("backspace!")
End If

所以你的整个代码将变成:

Private Sub TextBox10_KeyPress(ByVal sender As Object, ByVal e As     System.Windows.Forms.KeyPressEventArgs) Handles TextBox10.KeyPress

Dim allowedChars As String = "1234567890."

If allowedChars.IndexOf(e.KeyChar) = -1 andalso
Not e.KeyChar = ChrW(8) Then
' Invalid Character
e.Handled = True
End If

End Sub

类似问题:How can I accept the backspace key in the keypress event?

关于vb.net - 文本框不允许按退格键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8208691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com