简体   繁体   中英

Get Value of Backspaced Character

I have a form with a keyboard on it. When a user types a letter it works like a GPS Feature and will only allow you to type the next letter according to the predictions database.

Likewise, when someone makes a mistake, that letter will be blacked out

So far I have the following code that works to capture the letter they deleted

dim lastLetter = Mid(RTextBox.Text, RTextBox.Text.Length, 1)

However when the person presses backspace on their keyboard, the letter is already removed and will not work with the above code

Is there a way to capture that letter before it gets removed from the textbox?

You can do this in the keydown handler. In this example, c will have the character just backspaced over.

Private Sub rText1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
  Handles rText1.KeyDown

If e.KeyValue = Keys.Back Then c = rText1.Text.Chars(rText1.Text.Length - 1)
e.Handled = False

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM