在用VB6的RICHTEXTBOX控件做编辑窗口,现在出现了一个小问题:就是如何把一个TAB键屏蔽掉?也就是用户当敲入一个TAB键时,不要把焦点移到其它的控件上,要在编辑窗口中加入两个空格。
如何解决此问题?

解决方案 »

  1.   

    '这样
    Private Sub RichTextBox1_GotFocus()
    Dim TEMP As Control
    For Each TEMP In Me.Controls
        TEMP.TabStop = False
    Next
    End SubPrivate Sub RichTextBox1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 9 Then
        KeyAscii = 0
        SendKeys ("  ")
    End If
    End SubPrivate Sub RichTextBox1_LostFocus()
    Dim TEMP As Control
    For Each TEMP In Me.Controls
        TEMP.TabStop = True
    Next
    End Sub
      

  2.   

    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 9 Then
        KeyAscii = 0
        SendKeys ("  ")
    End If
    End Sub
    你用KeyDown事件替换KeyPress事件即可。
    KeyDown中的TAB的Keycode可以利用Debug.Print Keycode 得到。