Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

registerevent - Associate event handler for COM object event at run time

Syntax

h.registerevent(eventhandler)
registerevent(h, eventhandler)

Description

h.registerevent(eventhandler) registers event handler routines with their corresponding events. The eventhandler argument can be either a string that specifies the name of the event handler function, or a function handle that maps to that function. Strings used in the eventhandler argument are not case sensitive.

registerevent(h, eventhandler) is an alternate syntax.

COM functions are available on Microsoft Windows systems only.

Examples

Show events in the MATLAB sample control:

f = figure ('position', [100 200 200 200]);
h = actxcontrol ('mwsamp.mwsampctrl.2', [0 0 200 200], f);
h.events

MATLAB displays all events associated with the instance of the control (output is formatted):

   Click = void Click()
   DblClick = void DblClick()
   MouseDown = void MouseDown(int16 Button, int16 Shift, 
     Variant x, Variant y)
   Event_Args = void Event_Args(int16 typeshort, 
     int32 typelong, double typedouble, string typestring, 
     bool typebool)
 

Register all events with the same event handler routine, sampev:

h.registerevent('sampev');
h.eventlisteners

MATLAB displays:

ans = 
    'Click'         'sampev'
    'DblClick'      'sampev'
    'MouseDown'     'sampev'
    'Event_Args'    'sampev'
 

Register individual events:

%Unregister existing events
h.unregisterallevents;
%Register specific events
h.registerevent({'click' 'myclick'; ...
    'dblclick' 'my2click'});
h.eventlisteners

MATLAB displays:

ans = 
    'click'       'myclick' 
    'dblclick'    'my2click'
 

Register events using a function handle (@sampev) instead of the function name:

h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200]); 
registerevent(h, @sampev);

See Also

eventlisteners | events (COM) | isevent | unregisterallevents | unregisterevent

How To

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS