如何自动更改光标位置?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何自动更改光标位置?相关的知识,希望对你有一定的参考价值。

我在TextBox1上有TextBox2TextBox3TextBox4 TabPage。我想在每个TextBox中的1个字符后自动移动光标位置。我该如何解决这个问题?

答案

如果它们不在控件数组中,则为以下代码:

  Private Sub Text1_Change()
  If Len(Text1.Text) = 1 Then Text2.SetFocus
  End Sub

对于控制数组:

    Private Sub Text1_Change(Index as Integer)
  If Len(Text1(Index).Text) = 1 Then
     If Index < Text1.UBound Then
      Text1(Index + 1).Setfocus
    ElseIf Index = Text1.UBound Then  'this is optional, but it allows you to set the focus to
                                      'the command button after the last item so that they can
                                      'submit instead of sitting in the last textbox
      cmdSubmit.Setfocus
    End If
  End If
End Sub

以上是关于如何自动更改光标位置?的主要内容,如果未能解决你的问题,请参考以下文章