Handling Events in a LabVIEW User Interface
- Updated2025-07-23
- 3 minute(s) read
To handle an event in LabVIEW, you register a callback VI, which LabVIEW automatically calls when the control generates the event.
Complete the following steps to use the Register Event Callback function, available in the LabVIEW Full or Professional Development System.
- Wire the reference of the control that sends the event you want to handle to the Event input of the Register Event Callback function.
- Use the Event input terminal drop-down list to select the specific event you want to handle.
- When you want to pass custom data to the callback VI, wire the custom data to the User Parameter input of the Register Event Callback function. The User Parameter input can be any data type.
- Right-click the VI Ref input of the Register Event Callback function and select Create Callback VI from the context menu. LabVIEW creates an empty callback VI with the correct input parameters for the particular event, including an input parameter for any custom data you wired to the User Parameter input in step 3.
- Save the new callback VI. The block diagram that contains the Register Event Callback function now shows a Static VI Reference node wired to the VI Ref input of the function. This node returns a strictly typed reference to the new callback VI.
- Complete the block diagram of the callback VI to perform the operation you specify when the control generates the event.
- When the application finishes handling events for the control, use the Unregister for Events function to close the event callback refnum output of the Register Event Callback function.
The following figure shows how to register a callback VI to handle the Break event for the Application Manager control:
You can resize the Register Event Callback function node to show multiple sets of terminals to handle multiple events. Refer to the Simple OI - Configure Event Callbacks and to the Full UI - Configure Event Callbacks example user interface VIs for examples of registering and handling events from the TestStand User Interface (UI) Controls.
Optimizing Event Handling Performance
You must limit the tasks you perform in a callback VI to ensure that LabVIEW handles the event in a timely manner to allow the front panel to quickly respond to user input and prevent possible hang conditions. When a callback VI performs ActiveX operations that can process messages or performs TestStand operations that can call back into LabVIEW, the application must perform these operations outside of the callback VI. You can define a user event the callback VI generates to defer these types of operations.
The ReDraw user event in the full example user interface shows how callback VIs can defer operations to perform outside of the callback VI. The example user interface performs the following tasks:
- Calls the Full UI - Create LabVIEW Application Events VI to create the ReDraw user event.
- Callback VIs, such as the Full UI - Resized Event Callback VI, generate the ReDraw user event when the user interface must resize and reposition controls on the front panel.
- The ReDraw User Event case in the main event loop of the Full UI - Top-Level VI sets a global variable while processing the current event to prevent callback VIs from generating new ReDraw events. The ReDraw User Event case calls the Full UI - Disable Panel Updates VI to prevent the front panel from updating, calls the Full UI - ArrangeControls VI to update the position and size of controls on the front panel, and calls the Full UI - Re-enable Panel Updates VI to update the front panel.