Partager via


Binding, Raising, Unbinding, and Retrieving Events Sample

File: ...\Samples\Solution\Toledo\FrmEvents.scx

This sample demonstrates binding events, raising events programmatically, unbinding events, and retrieving events for _SCREEN system variable, or the main Visual FoxPro window. In the sample, you can manually raise a bound event for _SCREEN by selecting an event from the combo box or invoke the same events and their respective handlers by using the mouse.

For more information about _SCREEN, see _SCREEN System Variable.

Binding Events

To respond to Visual FoxPro events, use the BINDEVENT( ) function. In this sample, the BINDEVENT( ) function is called in the custom InitBindEvent method and binds several _SCREEN events to the form's methods. When one of the _SCREEN events fires, the associated handler method is called:

BINDEVENT(_SCREEN,"Resize",ThisForm,"screenresize")
BINDEVENT(_SCREEN,"Mousedown",ThisForm,"screenmousedown")
BINDEVENT(_SCREEN,"Mouseup",ThisForm,"screenmouseup")
BINDEVENT(_SCREEN,"Rightclick",ThisForm,"screenrightclick")
BINDEVENT(_SCREEN,"Dblclick",ThisForm,"screendblclick")

For more information, see BINDEVENT() Function and Init Event.

Raising Events Programmatically

To raise events programmatically, use the RAISEEVENT( ) function. In this sample, when the combo box is selected, the InteractiveChange event uses the returned value to programmatically raise the specified event.

RAISEEVENT(_SCREEN,this.Value) 

For more information, see RAISEEVENT() Function and InteractiveChange Event.

Unbinding Events

To unbind event handlers, use the UNBINDEVENTS( ) function. In this sample, the custom UnbindHandlers method unbinds events for _SCREEN.

UNBINDEVENTS(_SCREEN)

For more information, see UNBINDEVENTS() Function.

Retrieve Event Bindings

To retrieve existing event bindings into an array, use the AEVENTS( ) function. In this sample, the custom ScreenDblClick method, which is bound to the _SCREENDblClick event, uses the AEVENTS( ) function to report the number of event bindings:

AEVENTS(laEvents,Thisform)

For more information, see AEVENTS() Function, and DblClick Event.

See Also

Solutions Samples | Event Binding for Visual FoxPro Objects