当前位置: 开源爱好者 » 编程教程 » VB教程 » 正文

VB设置 text focus光标自动移动至下一个文本框

本代码演示在VB6.0的编程中,让文本框的光标移动变得更人性化和智能化,当用户输入完第一个Text内容后,光标Focus自动移动至下一个空白的输入框中,无需用户操作鼠标点击即可,大大提升用户输入效率,提升软件使用体验,以下代码是通过一个输入各科成绩判断奖学金等级的小程序,不演示光标的自动移动,软件界面如下:

 VB设置 text focus光标自动移动至下一个文本框

代码部分如下:

Private Sub Command1_Click()
Dim a1 As Boolean, a2 As Boolean, a3 As Boolean, a4 As Boolean
Dim m1 As Integer, m2 As Integer, m3 As Integer
m1 = Val(Text1)  '取文本框的值放到变量里
m2 = Val(Text2)
m3 = Val(Text3)'www.srcfans.com
a1 = (m1 >= 70 And m2 >= 70 And m3 >= 70)   '先写出三等奖学金的条件
If a1 Then Label5.Caption = "三等奖学金" Else Label5.Caption = "没有奖学金"
                            '用二支结构的单行写法完成三等奖学金的程序
a1 = (m1 + m2 + m3) / 3 >= 90             '平均分大于90分的条件
a2 = (m1 = 100 And m2 >= 75 And m3 >= 75) '或者其中一门是100其他不低于75分的条件
a3 = (m2 = 100 And m3 >= 75 And m1 >= 75)
a4 = (m3 = 100 And m1 >= 75 And m2 >= 75)
If a1 Or a2 Or a3 Or a4 Then Label5.Caption = "二等奖学金"  '判断二等奖学金条件

  a1 = (m1 + m2 + m3) / 3 >= 95       '平均分大于95分的条件
  a2 = (m1 = 100 And m2 = 100 And m3 >= 80)  '或者两门是100,另一门不低于80分的条件
  a3 = (m3 = 100 And m2 = 100 And m1 >= 80)
  a4 = (m1 = 100 And m3 = 100 And m2 >= 80)
  If a1 Or a2 Or a3 Or a4 Then Label5.Caption = "一等奖学金"  '符合以上条件的是一等奖学金
Text1.SetFocus            '判断完后文本框1内容被选中,等待用户新输入
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub

Private Sub Text1_LostFocus()
Text2.SetFocus
Text2.SelStart = 0
Text2.SelLength = Len(Text2)
End Sub

Private Sub Text2_LostFocus()
Text3.SetFocus
Text3.SelStart = 0
Text3.SelLength = Len(Text3)
End Sub

 更为完整的源码包:VB模拟输入的成绩判断奖学金等级

CopyRight 2018© 开源爱好者 All Rights Reserved 豫ICP备16030607号 隐私声明 网站地图