Keep focus on textbox after pressing enter

无人久伴 提交于 2019-12-05 07:47:25
Oneide

From the top of my head: try setting the KeyCode to 0. Also, use the KeyCodeConstants class (from the Core library) to determine what value the Enter key is.

Like this:

If KeyCode = KeyCodeConstants.vbKeyReturn Then
    CmdAddOtherAsset_Click
    KeyCode = 0
End If

Remove the line you're trying to set the focus on the other sub (TxtOtherAsset.SetFocus).

Hope it works for you. I did not test it.

Are you using the Enter key as a trigger to catch changes to the text box? If that's the case, try the After Update event instead. Also, take a look at the On Exit event. When I looked, I noticed it has a Cancel parameter. If you still want to catch the Enter key in the Key Down event, you could possibly the On Exit event to prevent leaving the text box. Of course, that probably means you're permanently stuck and may need to set up a way to allow exiting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!