Contents

registerevent

Associate event handler for COM object event at run time

Syntax

registerevent(h,eventhandler)

Description

registerevent(h,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.

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);
events(h)
   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)

MATLAB displays all events associated with the instance of the control.

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

registerevent(h,'sampev');
eventlisteners(h)
ans = 
    'Click'         'sampev'
    'DblClick'      'sampev'
    'MouseDown'     'sampev'
    'Event_Args'    'sampev'

Register individual events:

% Unregister existing events
unregisterallevents(h);
% Register specific events
registerevent(h,{'click' 'myclick'; ...
    'dblclick' 'my2click'});
eventlisteners(h)
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);
Was this topic helpful?