Events in Visual FoxPro
Events occur automatically when the system or application user performs a specific action. Events associated with an object occur when a user interacts with the object in any way, such as tabbing to it, clicking it, or moving the mouse pointer over it. For example, the CommandButton class contains a Click event that is triggered when the user clicks the command button.
You can add code to the event procedure of an object so that when the event occurs for the object, the code executes automatically. For example, you can add code to the Click event so that when the user clicks the command button, the code executes automatically to perform an action, such as opening a form. System events can also execute code in events as in the case of the Timer event in a Timer control.
The following table contains a list of the core set of Visual FoxPro events, which apply to most controls.
|Event||Event occurs when|
An object is created.
An object is released from memory.
The user clicks the object using the primary mouse button.
The user double-clicks the object using the primary mouse button.
The user clicks the object using the secondary mouse button.
The object receives the focus through user action such as tabbing or clicking or by changing the focus in code using the SetFocus Method. For more information, see SetFocus Method.
The object loses the focus through user action such as tabbing to or clicking another object or by changing the focus in code using the SetFocus method.
The user presses and releases a key.
The user presses the mouse button while the mouse pointer is over the object.
The user moves the mouse pointer over the object.
The user releases the mouse button while the mouse pointer is over the object.
Triggering Events Programmatically
Most events occur automatically when the system or user performs an action. However, you can generate the following events programmatically using certain Visual FoxPro commands:
Use the MOUSE command to generate the Click, DblClick, MouseMove, and DragDrop events.
Use the ERROR command to generate the Error event.
Use the KEYBOARD command to generate the KeyPress event.
Though you cannot trigger most events programmatically, you can call the procedure associated with the event, which executes the code in the event but does not trigger the event itself. For example, the following line calls the Activate event procedure for the form frmPhoneLog and executes the code in the event; however, it does not activate the form itself:
If you want to activate the form, use the form's Show method:
Calling the Show method displays and activates the form, which also executes the code in the Activate event.