FormLostFocus Event
The Form and MDIChild controls contain a FormLostFocus event which lets you create projects which track the amount of time specific, interrogated Forms/MDIChild Windows were in focus (active) while a project was loaded in Runtime.
The FormLostFocus event has a Duration argument which, when the event occurs, outputs the amount of time, in milliseconds, the Form/MDIChild was active prior to losing focus. The tally of the Duration value starts when the Form/MDIChild is shown or activated and ends when the form is deactivated or destroyed.
Note that a LostFocus event is also exposed for all targets. The two events are not directly related and the FormLostFocus event may not fire when the LostFocus event fires. The FormLostFocus event provides a Duration argument to specify how long that form was active. The LostFocus event does not contain the Duration argument.
This topic describes:
The FormLostFocus occurs when:
The user, application or automation causes focus to change to another Form/MDIChild (the event is raised even if the application is hidden or minimized at the time the focus changes).
The user or automation causes the Form/MDIChild to be minimized and another Form/MDIChild becomes active.
Changing from one application to another where the applications are child processes in a single adapter (HookChildProcesses set to True). The FormLostFocus event occurs when changing from the current child application's Form/MDIChild to another child application's Form/MDIChild.
Changing tabs in the TabbedReparentContainer control for Form/MDIChild controls within re-parented applications.
Changing application windows
using the Windows taskbar.
Note: When changing application
windows using the Windows taskbar, Studio may trigger the FormLostFocus
event for the same Form/MDIChild twice. The first event occurs when
the user clicks down on the Taskbar button to select another application
window, and then again when the user releases the mouse.
Changing between cloned instances of a Form/MDIChild. The event is raised when changing focus from one clone to another. The Duration values are tracked separately for each of the clones.
Changing Internet Explorer browser windows.
A pop-up dialog displays and receives focus (either modal or non-modal).
Form/MDIChild is rematched by automation executing the Rematch() method, or automation executing Adapter.RematchChildren() method.
An automation executes the Adapter.Hide() method making the Form/MDI Child no longer active.
An automation executes the Adapter.Stop(), Form.Close() or MDIChild.Close() method or the associated application is otherwise terminated.
When the FormLostFocus event occurs, a duration value is calculated and output as the FormLostFocus Duration event argument (Int32 type). OpenSpan tallies the amount of time, in milliseconds, during which the Form/MDIChild was in active prior to losing focus. The connection block below shows the Duration event argument.
The following automation shows using the FormLostFocus event and storing the Duration values in a table:
Note: The FormLostFocus event can and does occur after a Form has been destroyed (closed, application shutdown, and so on). Do not use the FormLostFocus event to access certain properties or to call methods on the form or its child controls since the Form and its controls may no longer be matched when the event occurs.
If you require using the FormLostFocus event to access properties or call methods for a form and/or its child controls, surround the execution path with Try/Catch blocks to catch any exceptions that may occur.
Capturing Form and Child Window Title with FormLostFocus
An additional value to the Event block lets you capture the form or child window title text as the FormLostFocus event fires.
How to Use the FormLostFocus Event with OpenSpan's Events Feature
You can use Generic and Custom event notifications with the Events feature to monitor Form and MDI Child window activity. These steps describe using the FormLostFocus event in a Generic events project.
Add the web or Windows adapter and set the StartPage or Path property.
Start Interrogation and interrogate at least one target in the application and then Stop Interrogation.
Set the MonitoredEventsMode property for the adapter to either All Controls or Interrogated Controls.
Browse the MonitoredEvents property and select Form and/or MDI Child under Target Type and FormLostFocus under Events on the Configure Monitored Events window.
Add and configure the EventServiceWebServiceConnector component to distribute events to the event notification service.
While running the project, event notifications are triggered when the Form/MDIChild focus changes as described in the When the FormLostFocus event occurs section of this topic. The Duration value is calculated and sent with the FormLostFocus event notification data.
Privacy | Trademarks | Terms of Use | Feedback
Updated: 18 June 2020
© 2016 - 2020 Pegasystems Inc. Cambridge, MA All rights reserved.