按Enter键,使光标自动移到下一控件,如何实现?

解决方案 »

  1.   

    Private Sub Form_Load()
     KeyPreview = True
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        SendKeys Chr$(9), True
    End If
    End Sub
      

  2.   

    通过设置焦点啊。比如遇回车
    if keyascii=13 then
     command1.setfocuse '(字母记不清了,你打程序时可以找到)
    end if
      

  3.   

    if keyascii=13 then  '判断是否按了回车键
       sendkeys"{TAB}"   '转换成TAB键
    end if
      

  4.   

    1.调用TAB  sendkeys"{TAB}"   
    2.直接指定 *.SetFocus最好不用第一种,编程可能简单一点但有时会死键盘。
      

  5.   

    @@@可以在keypress事件中设置下一个控件setfocus.@@@
    例:
    在text1中输入回车,焦点转移到text2:
    private sub key_press(keyascii as integer)
    if keyascii=13 then text2.setfocus
    end sub
    如果是在commandbutton一类的控件上使用,就要用api了。我不会。
      

  6.   

    在控制的keydown或者keypress事件中
    if keyascii=13 then
     sendkeys "{Tab}"
    end if
      

  7.   

    大家可以一齐来讨论下!
    使用Sendkeys "{Tab}"在win2K下有时会遇到键盘锁死的状况发生,并且Num Lock指示灯闪烁,有Beep的声音,如何让解决?
    先 Thanks very much 大家!
      

  8.   

    '看看Num Lock指示灯还闪不闪
    Private Declare Function GetNextDlgTabItem Lib "user32" (ByVal hDlg As Long, _
            ByVal hCtl As Long, ByVal bPrevious As Long) As Long
    Private Declare Function SetDlgFocus Lib "user32" Alias "SetFocus" _
           (ByVal hwnd As Long) As Long'移到下一个可Focus的Control
    Private Sub NextDlg()
    Dim hwnd5 As Long
    hwnd5 = GetNextDlgTabItem(Me.hwnd, Screen.ActiveControl.hwnd, 1)
    Call SetDlgFocus(hwnd5)
    End Sub'移到上一个可Focus的Control
    Private Sub PrevDlg()
    Dim hwnd5 As Long
    hwnd5 = GetNextDlgTabItem(Me.hwnd, Screen.ActiveControl.hwnd, 0)
    Call SetDlgFocus(hwnd5)
    End SubPrivate Sub Form_Load()
     KeyPreview = True
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
     If KeyCode = 13 Then
        NextDlg
     End If
    End Sub
      

  9.   

    if key=#13 then
    selectnext(activecontral,0,0)
      

  10.   

    以 yefanqiu(叶帆)的方法,还是没有取消电脑 Beep 的声音。
    再繁各位想想折.
      

  11.   

    1.所有控件的tabindex必须是正确有序的
    2.sendkeys "{tab}",tabindex为当前控件tabindex+1的控件
    3.在form_keypress事件中:
    if keyascii=13 then 
       keyascii=0
       yourobj.enable=true
       yourobj.setfocus
    endif
      

  12.   

    不好意思,已经有人帮忙找到了一种较好的方法,楼上的各位可以试试。
    本贴就此结了。谢谢大家。
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_TAB = &H9Public Sub KeyNext(ByRef KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            keybd_event VK_TAB, 0, 0, 0
            keybd_event VK_TAB, 0, KEYEVENTF_KEYUP, 0
            KeyAscii = 0
        End If
    End Sub