Share via


Assigning Code to Events

Unless you associate code with an event, nothing happens when that event occurs. You'll almost never write code for all of the events associated with any Visual FoxPro object, but you'll want to incorporate functionality in response to certain key events in your applications. To add code to be executed when an event occurs, use the Properties window in the Form Designer.

The sequence of events affects where you should put code. Keep in mind the following tips:

  • The Init events of all the controls on a form execute before the Init event of the form, so you can include code in the Init event of the form to manipulate any of the controls on the form before the form is displayed.
  • If you want some code to be processed whenever the value of a list box, combo box, or check box changes, associate it with the InteractiveChange event. The Click event might not occur or might be called even if the value hasn't changed.
  • When you are dragging a control, the other mouse events are suspended. For example, the MouseUp and MouseMove events do not occur during a drag-and-drop operation.
  • The Valid and When events return a value. True (.T.) is the default. If you return false (.F.) or 0 from the When event, the control cannot get the focus. If you return false (.F.) or 0 from the Valid event, the focus cannot leave the control.

For more information about using the Form Designer, see Creating Forms. For information on coding classes and adding event code, see Object-Oriented Programming.

See Also

Tracking Event Sequences | Events in Visual FoxPro | Assigning Code to Events | Understanding the Event Model