在KeyPress事件中捕获, KeyAscii应该是  9

解决方案 »

  1.   

    我不是太明白你的意思,你想用tab键干什么?
      

  2.   

    我要在用戶輸入tab鍵時產生三個空格,該怎么辦呢各种事件我都試過,請高手指點一二
      

  3.   

    如果是这样的话,我认为是用keypress为好
    if keyascii=tab键的ascii码 then
    text1.setfocus
    text1.text="   "
    endif
      

  4.   

    是這樣的,當我在text1 get focus時按下tab鍵,根本就不發生press等事件
      

  5.   

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 9 Then
        Dim ctrl As Control
        Set ctrl = Me.ActiveControl
        ctrl.Enabled = False
        ctrl.Enabled = True
    End If
    End SubPrivate Sub Form_Load()
    On Error Resume Next
    Dim ctrl As Control
    For Each ctrl In Me.Controls
        ctrl.TabStop = False
    Next
    End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 9 Then
        MsgBox "you pressed TAB"
        'KeyCode = 0
    End If
    End Sub
      

  6.   

    bcpl()謝謝你的解答可是我不可能設定所有的控件的tabstop為false
    你知道有什么Api可以解決的嗎
      

  7.   

    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer 
         
        Private Sub Text1_LostFocus() 
         If GetKeyState(vbKeyTab) < 0 Then 
            Text1.SetFocus 
            Msgbox "按了tab键"
         End If 
        End Sub 
    'from china-askpro.com
      

  8.   

    我找到更好的方法:
    Private Sub Text1_Validate(Cancel As Boolean)
     If GetKeyState(vbKeyTab) < 0 Then
        Cancel = True
        MsgBox "按了tab?"
     End If
    End Sub