各位好,我刚学VB6.0不久,下面有个问题想请教一下大家
我定义了四个文本框数组text1,text2,text3,text4
它们在窗体中是这样排列的
text1(1) text2(1) text3(1) text4(1)
text1(2) text2(2) text3(2) text4(2)
text1(3) text2(3) text3(3) text4(3)
我想编一段键盘代码,当按下键盘的方向键光标就会根据方向键所指的方向跳到相邻的文本框去,但
刚学不太会,请大家不吝指点一下,谢谢!

解决方案 »

  1.   

    设置textbox的tabstop的循序就可以了吧。
      

  2.   

    我是菜鸟:Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
        Case 38     '上方向键
            If Index = 1 Then
                Text1(3).SetFocus
            Else
                Text1(Index - 1).SetFocus
            End If
        Case 40     '下方向键
            If Index = 3 Then
                Text1(1).SetFocus
            Else
                Text1(Index + 1).SetFocus
            End If
        Case 37     '左方向键
            Text4(Index).SetFocus
        Case 39     '右方向键
            Text2(Index).SetFocus
        End Select
    End Sub'其它几个事件差不多,如下:Private Sub Text2_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
        Case 38     '上方向键
            If Index = 1 Then
                Text2(3).SetFocus
            Else
                Text2(Index - 1).SetFocus
            End If
        Case 40     '下方向键
            If Index = 3 Then
                Text2(1).SetFocus
            Else
                Text2(Index + 1).SetFocus
            End If
        Case 37     '左方向键
            Text1(Index).SetFocus
        Case 39     '右方向键
            Text3(Index).SetFocus
        End Select
    End SubPrivate Sub Text3_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
        Case 38     '上方向键
            If Index = 1 Then
                Text3(3).SetFocus
            Else
                Text3(Index - 1).SetFocus
            End If
        Case 40     '下方向键
            If Index = 3 Then
                Text3(1).SetFocus
            Else
                Text3(Index + 1).SetFocus
            End If
        Case 37     '左方向键
            Text2(Index).SetFocus
        Case 39     '右方向键
            Text4(Index).SetFocus
        End Select
    End SubPrivate Sub Text4_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
        Case 38     '上方向键
            If Index = 1 Then
                Text4(3).SetFocus
            Else
                Text4(Index - 1).SetFocus
            End If
        Case 40     '下方向键
            If Index = 3 Then
                Text4(1).SetFocus
            Else
                Text4(Index + 1).SetFocus
            End If
        Case 37     '左方向键
            Text3(Index).SetFocus
        Case 39     '右方向键
            Text1(Index).SetFocus
        End Select
    End Sub