External Interfaces Reference |
Register event handler with control's event
Syntax
Description
h.registerevent(event_handler)
registers certain event handler routines with their corresponding events. Once an event is registered, the control responds to the occurrence of that event by invoking its event handler routine. The event_handler
argument can be either a string that specifies the name of the event handler function, or a function handle that maps to that function.
registerevent(h, event_handler)
is an alternate syntax for the same operation.
You can either register events at the time you create the control (using actxcontrol
), or register them dynamically at any time after the control has been created (using registerevent
). Both events and event handlers are specified in the event_handler
argument (see "Specifying Event Handlers" in the External Interfaces documentation).
Example 1
Create an mwsamp
control and list all events associated with the control:
f = figure ('position', [100 200 200 200]); h = actxcontrol ('mwsamp.mwsampctrl.2', [0 0 200 200], f); h.events ans = Click = void Click() DblClick = void DblClick() MouseDown = void MouseDown(int16 Button, int16 Shift, Variant x, Variant y)
Register all events with the same event handler routine, sampev
. Use the eventlisteners function to see the event handler used by each event:
h.registerevent('sampev'); h.eventlisteners ans = 'click' 'sampev' 'dblclick' 'sampev' 'mousedown' 'sampev' h.unregisterallevents;
Register the Click
and DblClick
events with event handlers myclick
and my2click
, respectively:
h.registerevent({'click' 'myclick'; 'dblclick' 'my2click'}); h.eventlisteners ans = 'click' 'myclick' 'dblclick' 'my2click'
Example 2
Register all events with the same event handler routine, sampev
, but use a function handle (@sampev
) instead of the function name:
See Also
events
, eventlisteners
, unregisterevent
, unregisterallevents
, isevent
propedit | release |
© 1994-2005 The MathWorks, Inc.