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?
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:
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Command1.Caption = "Limit Cursor Movement"
Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
'Get information about our wndow
GetClientRect Me.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Convert window coördinates to screen coördinates
ClientToScreen Me.hWnd, upperleft
'move our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub Command2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub