logo

Events

Events are SUBSS (subroutines) that are triggered after the controls in your form are manipulated at runtime. This is a central part of InForm's functionality because it is where you write the code to respond to the controls.

Simulate a click

Simulating a click can be useful during testing of your application. To generate a click programmatically, you can call the __UI_Click sub directly, passing the name (ID) of the control you want to "click." For example:

__UI_Click Button1

Control-specific events

The following events are specific to toolbox controls:

FocusIn/FocusOut

FocusIn:
The FocusIn event occurs when a control gains focus.

FocusOut:
The FocusOut event is triggered when a control loses focus.
If another control has focus when a FocusIn event is triggered, a FocusOut event occurs first for such a control.

SetFocust:
You can set focus to a control programmatically with the SetFocus method.

Syntax:

SetFocus ControlID

Example:

SetFocus Button1

KeyPress

The KeyPress event occurs when a control has focus and the user presses any key on the keyboard. The following variables are made available:

Variables __UI_CtrlIsDown, __UI_AltIsDown, and __UI_ShiftIsDown are global variables that hold true when the key they represent is being held down. Global variables affect the drawing, input, or event dispatcher routines, and their names always start with the UI prefix.

The __UI_KeyHit variable can be modified to pass different values to the control that has focus, as the KeyPress event is triggered before the keypress is actually processed.

__UI_KeyHit is a global variable of type LONG INTEGER that holds the scan code of the last key pressed by the user. Positive values indicate a key was pressed, and negative values indicate a key was released.

This variable can be accessed anywhere, but it is usually manipulated in KeyPress event handlers, especially for Textbox controls, as it can be used to change the key presses that actually get sent to the control.

Mouse Click

Click events are triggered when a control is active and visible, and the user presses the left mouse button while hovering over the control, and releases the button while still hovering over the same control.

MouseDown/MouseUp

The MouseDown event occurs when the left mouse button is first pressed on a control. The MouseUp event is triggered when the left mouse button is released on a control. Immediately after a MouseUp event is fired, a Click event is also triggered.

MouseEnter/MouseLeave

The MouseEnter event occurs when the mouse pointer enters a control's rectangular area. The MouseLeave event is triggered when the cursor leaves the rectangular area of a control.

By adding code to these two events, you can, for example, emulate a hovering effect such as changing a control's background color when MouseEnter is triggered and restoring it when MouseLeave is executed.

TextChanged

The TextChanged event is triggered whenever a textbox control is edited by the user. It occurs after the text is changed, allowing you to access it using the Text property.

Text values are accessible via an array of variable-width STRINGS, using the control's ID: Text(ControlID) = "Your text"

ValueChanged

The ValueChanged event is triggered whenever a List, Dropdown list, Track bar, CheckBox, or Toggle switch control is manipulated by the user. It occurs after an item is selected, after the TrackBar value is changed, or after the control is clicked. You can access the Value property in this event handler.

Other events

BeforeInit

The BeforeInit event is fired just before your form is displayed to the user. Any code placed in this event handler will run once at startup.

The global variable __UI_KeepScreenHidden can be set to True if you do not want InForm to show the main form immediately. This is useful when your program needs to perform any startup routines before displaying the main form.

In the BeforeInit event, set this variable to True to avoid showing the form immediately.

Caution: If you do set __UI_KeepScreenHidden to True, remember to use _SCREENSHOW somewhere later in your program. Otherwise, your main form will never be displayed, and your program will continue running as a hidden window.

BeforeUnload

The BeforeUnload event is triggered right before your form is closed, providing an opportunity to perform cleanup routines or save data before exiting the program.

If you want to cancel the close request, set the __UI_UnloadSignal variable to False.

The global variable __UI_UnloadSignal is automatically set to True when the user requests to close the program, either by clicking the X button on the title bar or by using Alt+F4 (Windows only).

In a BeforeUnload event, set this variable to False to cancel the quit request and prevent the program from closing.

BeforeUpdateDisplay

The BeforeUpdateDisplay event is triggered at approximately 30 frames per second (fps), just before your form is repainted.

You can adjust the refresh rate to a higher number (but not lower than 30) by using the SetFrameRate method:

SUB __UI_OnLoad
    SetFrameRate 60
END SUB

For most programs treat SUB __UI_BeforeUpdateDisplay as if it was your main program loop.

FormResized

This event is triggered when a form with the CanResize property is resized at runtime.

OnLoad

The OnLoad event is triggered immediately after your form has been created in memory and displayed to the user. Any code added here will only run at startup.