This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Unregister event handler associated with COM object event at run time




unregisterevent(h,eventhandler) unregisters specific event handler routines from their corresponding events. Once you unregister an event, the object no longer responds to the event.

You can unregister events at any time after creating a control. The eventhandler argument, which is a cell array, specifies both events and event handlers.


Specify events in the eventhandler argument using the names of the events. Character vectors used in the eventhandler argument are not case-sensitive. unregisterevent does not accept numeric event identifiers.

COM functions are available on Microsoft® Windows® systems only.


Unregister events for a control.

  1. Create an mwsamp control and register all events with the same handler routine, sampev. Use eventlisteners to see the event handler used by each event. In this case, each event, when fired, calls sampev.m.

    f = figure('position',[100 200 200 200]);
    h = actxcontrol('mwsamp.mwsampctrl.2',[0 0 200 200],f,'sampev');
    ans = 
        'Click'         'sampev'
        'DblClick'      'sampev'
        'MouseDown'     'sampev'
        'Event_Args'    'sampev'
  2. Unregister just the dblclick event. Now, when you list the registered events using eventlisteners, dblclick is no longer registered and the control does not respond when you double-click the mouse over it.

    unregisterevent(h,{'dblclick' 'sampev'})
    ans = 
        'Click'         'sampev'
        'MouseDown'     'sampev'
        'Event_Args'    'sampev'
  3. Register the click and dblclick events with a different event handler for myclick and my2click, respectively.

    registerevent(h,{'click' 'myclick'; 'dblclick' 'my2click'});
    ans = 
        'click'       'myclick' 
        'dblclick'    'my2click'
  4. Unregister these same events by specifying event names and their handler routines in a cell array. eventlisteners now returns an empty cell array, meaning that no events are registered for the mwsamp control.

    unregisterevent(h,{'click' 'myclick'; 'dblclick' 'my2click'})
    ans = 

Unregister Microsoft Excel® workbook events:

  1. Create a Workbook object and register two events with the event handler routines, EvtActivateHndlr and EvtDeactivateHndlr. MATLAB® shows the events with the corresponding event handlers.

    myApp = actxserver('Excel.Application');
    wbs = myApp.Workbooks;
    wb = Add(wbs);
    registerevent(wb,{'Activate' 'EvtActivateHndlr'; 'Deactivate' 'EvtDeactivateHndlr'})

    ans = 
        'Activate'      'EvtActivateHndlr'  
        'Deactivate'    'EvtDeactivateHndlr'
  2. Unregister the Deactivate event handler. MATLAB shows the remaining registered event (Activate) with its corresponding event handler.

    unregisterevent(wb,{'Deactivate' 'EvtDeactivateHndlr'})
    ans = 
        'Activate'    'EvtActivateHndlr'

Introduced before R2006a

Was this topic helpful?