Results 1 to 2 of 2

Thread: Make sure lostfocus/validate event triggers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    91

    Make sure lostfocus/validate event triggers

    In general when you have a textbox normally best to use the validate or lostfocus event to execute some code when the focus is lost on that textbox (so when editing the textbox is done execute the code)

    This normally is fine when staying inside vb forms,
    but when changing from the VB form to let say notepad or word external application, the focus stays on the VB form's textbox and no code is executed and i do want te code to be executes, so maybe i have to force a lostfocus event when de form is no more activated (i allso tried to use the form events deactive, lostfocus and no succes, they are not triggered)
    Any idea's?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Make sure lostfocus/validate event triggers

    If your app does not require them to do something in notepad, etc., then you can use the ClipCursor API to limit the user to the form. Here's an example from the API Guide. It requires a form with two command buttons.
    VB Code:
    1. Private Type RECT
    2.     left As Long
    3.     top As Long
    4.     right As Long
    5.     bottom As Long
    6. End Type
    7. Private Type POINT
    8.     x As Long
    9.     y As Long
    10. End Type
    11. Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
    12. Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
    13. Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
    14. Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
    15. Private Sub Form_Load()
    16.     'KPD-Team 1999
    17.     'URL: [url]http://www.allapi.net/[/url]
    18.     'E-Mail: [email][email protected][/email]
    19.     Command1.Caption = "Limit Cursor Movement"
    20.     Command2.Caption = "Release Limit"
    21. End Sub
    22. Private Sub Command1_Click()
    23.     'Limits the Cursor movement to within the form.
    24.     Dim client As RECT
    25.     Dim upperleft As POINT
    26.     'Get information about our wndow
    27.     GetClientRect Me.hWnd, client
    28.     upperleft.x = client.left
    29.     upperleft.y = client.top
    30.     'Convert window coördinates to screen coördinates
    31.     ClientToScreen Me.hWnd, upperleft
    32.     'move our rectangle
    33.     OffsetRect client, upperleft.x, upperleft.y
    34.     'limit the cursor movement
    35.     ClipCursor client
    36. End Sub
    37. Private Sub Command2_Click()
    38.     'Releases the cursor limits
    39.     ClipCursor ByVal 0&
    40. End Sub
    41. Private Sub Form_Unload(Cancel As Integer)
    42.     'Releases the cursor limits
    43.     ClipCursor ByVal 0&
    44. End Sub

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