Replace 替换文本框中的字符?

Replace 替换文本框中的字符?,replace,vb6,keystroke,Replace,Vb6,Keystroke,在vb6中,我希望能够检测到用户何时按下空格键,并使用下划线符号代替空格。这是一种可能性还是我只是抱着希望?我似乎不太明白如何做到这一点,我试图摆弄与按键方法,但我不知道正确的代码来做到这一点 Private Sub txtbarcode_KeyPress(KeyAscii As Integer) if keyascii = vbkeyspace then 'replace space with underscore end if end sub 这应该行得通 Private Sub

vb6
中,我希望能够检测到用户何时按下空格键,并使用下划线符号代替空格。这是一种可能性还是我只是抱着希望?我似乎不太明白如何做到这一点,我试图摆弄与按键方法,但我不知道正确的代码来做到这一点

Private Sub txtbarcode_KeyPress(KeyAscii As Integer)
 if keyascii = vbkeyspace then
 'replace space with underscore
 end if

end sub
这应该行得通

Private Sub txtbarcode_KeyPress(KeyAscii As Integer)
 If KeyAscii = 32 Then
     'replace space with underscore
     KeyAscii = 95
 End If
End Sub