CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 1999
    Posts
    3

    LostFocus Handling

    Hi all,

    I am wondering how to force execution of LostFocus Event handler before the event causing it (mouse click on an other control for example); any idea ?

    Thanks
    Ahmed


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: LostFocus Handling

    if you need this for input validation, better check out the Validate Event in VB 6!


  3. #3
    Join Date
    Aug 1999
    Posts
    3

    Re: LostFocus Handling

    Actually I am using VB4 for this code !!
    Any solution ?


  4. #4
    Join Date
    Apr 1999
    Location
    Brooklyn, NY USA
    Posts
    171

    Re: LostFocus Handling

    For validation purposes in VB prior to version 6 I used to use this technic:

    private intFocus as Integer
    private Sub Text1_LostFocus()
    If IsTextValid(Text1) = false And (intFocus = -1 Or intFocus = Text1.TabIndex) then
    MsgBox "Not valid data in Text1.", , "Warning!"
    intFocus = Text1.TabIndex
    Text1.SetFocus
    else
    intFocus = -1
    End If

    End Sub

    private Sub Text2_LostFocus()
    If IsTextValid(Text2) = false And (intFocus = -1 Or intFocus = Text2.TabIndex) then
    MsgBox "Not valid data in Text2.", , "Warning!"
    intFocus = Text2.TabIndex
    Text2.SetFocus
    else
    intFocus = -1
    End If

    End Sub
    private Function IsTextValid(txt as Control) as Integer
    'this function analizes contents of the text property of the control (except maskedit box)
    If txt.Text = "" then
    IsTextValid = false
    else
    IsTextValid = true
    End If
    End Function




    To test place 2 text boxes on the form with text properties = "" and try to change the focus. Until you enter anything you will not be able to do that. You can customize IsTextValid function to do everything you want.
    HTH
    Vlad


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: LostFocus Handling


    private Sub Text1_LostFocus()
    If Text1.Text = "" then
    MsgBox "bad: field must be filled"
    DoEvents ' important
    Text1.SetFocus
    End If
    End Sub





  6. #6
    Join Date
    Aug 1999
    Posts
    3

    Re: LostFocus Handling

    Thanks For All repliers; it worked fine (for controls).

    For Menu Commands I had to do more stuff.

    Ahmed


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured