一个文本框用来输入日期,相邻的一个button用来调用时钟控件来向文本框中输入日期,(文本框tagindex = 1,button的tagindex = 2)。
现在有一个对日期的判断处理,一定要在文本框的lost_focus事件里作,但要求点击上面提到的button时不作对日期的判断处理,不知道该怎么处理了,请教高手
(在文本框上用tab键移动到button上时,要进行对日期的判断处理)

解决方案 »

  1.   

    dim flag as booleanprivate sub text1_lostfocus()
    flag = true
    end subprivate sub command1_setfocus()
    if flag then
        flag = false
        exit sub
    else
    '判断日期,处理
    endif
    end sub 
    这样如何?
      

  2.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 9 Then
            MsgBox "处理失去焦点"
        End If
    End Sub
      

  3.   

    谢谢楼上
    to rainivy(Rain):
    如果 判断日期处理 一定要在text1_lostfocus()中呢?(式样书变态:))to dongge2000
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    End SubPrivate Sub Text1_LostFocus()
    End Sub
    都设置了断点,可是直接就走了Text1_LostFocus()
    继续请教
      

  4.   

    用Tab和鼠标离开Text1都是直接执行Text1_LostFocus()
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    End Sub
    这些事件只有在按下除Tab外的其它健才会首先执行
      

  5.   

    呵呵!这个问题很有趣!
    你要明白VB控件焦点转移时事件的发生顺序,
    焦点转移时,当前焦点控件先发生lostfocus事件,然后获得焦点的控件发生GotFocus事件。可见在text1_lostfocus时,还不知道下一个获得焦点的控件是谁!
    怎么能让程序确定将来发生的事呢?这本不是什么难事,但你若非要这么“变态”的要求答案的话,此题“无解”!
      

  6.   

    Private Sub Form_Load() '
        Command2.TabIndex = 0
        Text1.TabIndex = 1
        Command1.TabIndex = 2
        Command1.CausesValidation = False
    End SubPrivate Sub Text1_Validate(Cancel As Boolean)
        If Not IsDate(Text) Then MsgBox "err"
        Cancel = True
    End Sub
      

  7.   

    上面还缺少一个输入日期事件Private Sub Command1_Click()
        Text1 = Format(Now, "yyyy-mm-dd")
    End Sub
      

  8.   

    Private Sub Command1_Click()
        Text1 = Format(Now, "yyyy-mm-dd")
    End SubPrivate Sub Form_Load() '
        Command2.TabIndex = 0
        Text1.TabIndex = 1
        Command1.TabIndex = 2
        Command1.CausesValidation = False
    End SubPrivate Sub Text1_Validate(Cancel As Boolean)
        If Not IsDate(Text1) Then
            MsgBox "err"
            Cancel = True
        End If
    End Sub
      

  9.   

    不知道是不我理解错误,感觉这个题有点难度。是不是可以理解为当按button 时不管text中的是不是日期都可以跳焦点?如果是样的话那问题就变成了如何在焦点跳转前知道是哪个控件将获得焦点