是在text.text输入完回车后,焦点落到command1上

解决方案 »

  1.   

    Private Sub Text8_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyReturn Then Command1.SetFocus
    End Sub
      

  2.   

    Private Sub Text8_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then    'return
       KeyAscii = 0
       conmmand1.SetFocus
    End If
    End Sub
      

  3.   

    EpopeeLei:
    谢谢你
        但是我用
      Private Sub Text8_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        command1.setfocus
    End If
    End Sub
    为什么不可以呢?
      

  4.   

    private sub text1_keydown(......)
    if keycode=13 then text2.setfocus
    end subcommand1同理。更省事的方法,所有textbox做成一个控件数组。也就是做第一个时,在属性列表中将其index属性改为0;以后添加的统统是text1,index递增。
    然后将textbox以及command1的tabindex顺序排好。Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
       ByVal lParam As Long) As LongConst WM_KEYDOWN As Long = &H100
    Const VK_TAB As Long = &H9
    Dim retVal as longprivate sub text1_keydown(......)
    if keycode=13 then retVal = PostMessage(Me.hwnd, WM_KEYDOWN, VK_TAB, 0)
    end sub原理是将回车更换为Tab键发出。
    使用API代替sendkeys "{Tab}"的原因是,后者在win2000下可能锁死键盘。
      

  5.   

    俺对VB不熟悉,只知道SetFocus API函数
      

  6.   

    Form1.KeyPreview = True在 Form1 的 KeyPress 事件中
      If KeyAscii = vbKeyReturn Then
        SendKeys "{Tab}"
      End If
    可以使窗体的焦点转移到下一个控件中。
      

  7.   

    要用keydown,keypress不相应回车。
      

  8.   

    albertina() 
        你的方法我用了好象不行
      

  9.   

    我还有一个问题
    Private Sub Text5_KeyPress(KeyAscii As Integer)
      If KeyAscii = 13 Then
        Me.Controls(12).SetFocus
      End If
    End Sub
    这个句子中的Me.Controls(12).SetFocus是什么意思
      

  10.   

    如果用keypress事件,得改掉form的keypress属性。
      

  11.   

    form的Keypreview属性要设置为false
      

  12.   

    先设置以下窗体上的TABELINDEX!
      

  13.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Command1.SetFocus
    End If
    End Sub
      

  14.   

    先设置控件的TabIndex。(最先获得焦点的为0,然后依次……)
    在from的keypress事件中加
    if keyAscii=13 then
      sendKeys "{Tab}"
    End if
    一切搞定!
      

  15.   

    主要是设置控件的TabIndex,依次排序既可。。如第一个获得焦点的为0,第二个获得焦点的为1
    在from的keypress事件中加
    if keyAscii=13 then
      sendKeys "{Tab}"
    End if