Documentation Center

  • Trial Software
  • Product Updates

Contents

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
   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:

h.registerevent('sampev');
h.eventlisteners
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
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

| | | |

Was this topic helpful?