I want to allow the user to enter symbols using the keyboard. I’m checking the textbox onkeydown event for the pressed key and then change it to a symbol, for example if I would press ‘a’ then the textbox would show ‘☺’. But the problem is that the textbox shows both ‘a’ and ‘☺’. Is there a better event to check this, or better way to do this?
Private Sub TextBox_KeyDown(sender as object, e as keyeventargs) handles TextBox.KeyDown
Select Case e.key
Case 'a'
TextBox.text += '☺'
End Select
End Sub
Try using the
KeyPressevent. In that event handler, you’ll want to set theHandledproperty of theKeyPressEventArgsto true to keep theakey from getting added to the textbox.