VB 中我想用回车来切换光标,如何实现?

来源:百度知道 编辑:UC知道 时间:2024/05/09 19:49:22
我的想法是 : 用TAB的ASCII值代替回车的
程序如下
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 9
End Sub

这个没成功.如果把9换成47,则按回车输入"/"没问题.

设置form的KeyPreview属性为true
form的KeyDown事件中写下:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
SendKeys "{tab}+{home}"
End If
End Sub

提醒你一个错误呵
keypress<>keycode

ASCII码可不等于键位码呵....

如上所说form的KeyPreview属性为true
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then KeyCode = 9
End If

你想用Tab键改变控件焦点吧:现在想换成回车改变焦点对吗?
可以直接写成这样的:
Private 需要按回车的空间 Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
要获得焦点的控件.SetFocus
End IF
End Sub
例如:在command1上按回车,text1获得焦点
Private Sub Command1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
End If
End Sub