假如前一个TextBox所输入的内容不符合条件则把焦点返回前一个TextBox。请众多高手指点迷津。

解决方案 »

  1.   

    validate事件中写代码
    SETFOCUS方法
      

  2.   

    在textbox的GotFocus事件中判断前一个textbox
      

  3.   

    我用您所说的方法试了,虽然用了setfocus方法,但在输入时,我故意把第一个TextBox输错,然后移动光标到第二个TextBox,但却不能把输入焦点返回第一个TextBox,这是为什么?
      

  4.   

    xfflean,如果焦点移到了最后一个TextBox呢?那又该怎么办?
      

  5.   

    你总该有个command或其它控件在保存或处理txt中的内容吧
    在这里判断啊
      

  6.   

    Private Sub Text2_GotFocus()
       If IsNumeric(Text1.Text) = False Then '判断TextBox.Text是否是数字
           Text1.Text = ""
           Text1.SetFocus
       End If
    End Sub
      

  7.   

    Private Sub Text2_GotFocus()
       If IsNumeric(Text1.Text) = False Then '判断Text1.Text是否是数字
           Text1.Text = ""
           Text1.SetFocus
       End If
    End Sub
      

  8.   

    piaoyang80(飘洋):我是要这样编的:共有13个textbox,顺序是年、月、日、编号、借款摘要、借款金额、还款时间、备注、总经理、部门经理、财务经理、财务经办、借款人。其中要判断年份是4位数字不能留空、月份是1-12、日是1-31、编号取年的最后两位+月+记录数,必填项是年、月、日、编号、借款摘要、借款金额、还款时间、财务经办、借款人,你说要怎样编?:)我是初学者,所以很多东西还不是很懂,希望多多指教。
      

  9.   

    感谢以下朋友提供的帮助:bdzwc(bdzwc) xfflean(雄) piaoyang80(飘洋) weixiaohua(我爱Delphi)
      

  10.   

    为什么不试一下,在LostFocuse中写判断代码呢?这样就不用考虑控件的顺序问题了。
      

  11.   

    Private Sub Text1_LostFocus()
      If Text1.Text ...... Then '判断Text1.Text是否是合法,如果不合法
          Text1.Text = ""
          Text1.SetFocus
      End If
    End Sub 
      

  12.   

    希望我得这段代码对你有帮助.由于时间紧日和月的判断上不完善,如果需要我可以给你写全.Option Explicit
    Dim IsTrue As Boolean
    Function Is_True(Str As String, FText As TextBox)
       If IsTrue = False Then
          IsTrue = True
          Exit Function
       End If
        Select Case Str
           Case "Year"
              If Len(FText.Text) <> 4 And IsNumeric(FText.Text) = False Then
                 MsgBox ("输入的日期无效")
                 FText.SetFocus
                 FText.Text = ""
                 IsTrue = False
              End If
           Case "Month", "Day"
              If Len(FText.Text) <> 2 And IsNumeric(FText.Text) = False Then
                 MsgBox ("输入的日期无效") '
                 FText.SetFocus
                 FText.Text = ""
                 IsTrue = False
              End If
         End Select
    End FunctionPrivate Sub Form_Load()
        IsTrue = True
    End SubPrivate Sub Text2_LostFocus()
        Is_True "Year", Text2
    End SubPrivate Sub Text3_LostFocus()
        Is_True "Year", Text3
    End SubPrivate Sub Text1_LostFocus()
        Is_True "Year", Text1
    End Sub
      

  13.   

    不好意思3个Text的LostFocus的事件弄错了.
    Private Sub Text2_LostFocus()
        Is_True "Month", Text2
    End SubPrivate Sub Text3_LostFocus()
        Is_True "Day", Text3
    End SubPrivate Sub Text1_LostFocus()
        Is_True "Year", Text1
    End Sub