Documentation Center

  • Trial Software
  • Product Updates

Contents

unregisterevent

Unregister event handler associated with COM object event at run time

Syntax

h.unregisterevent(eventhandler)
unregisterevent(h, eventhandler)

Description

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

unregisterevent(h, eventhandler) is an alternate syntax.

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.

h.unregisterevent({'event_name',@event_handler});

Specify events in the eventhandler argument using the names of the events. Strings 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.

Examples

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');
    h.eventlisteners
    
    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:

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

    h.unregisterallevents;
    h.registerevent({'click' 'myclick'; ...
        'dblclick' 'my2click'});
    h.eventlisteners
    
    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:

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

Unregister Microsoft Excel® workbook events:

  1. Create a Workbook object and register two events with the event handler routines, EvtActivateHndlr and EvtDeactivateHndlr:

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

    MATLAB® shows the events with the corresponding event handlers.

  2. Next, unregister the Deactivate event handler:

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

    MATLAB shows the remaining registered event (Activate) with its corresponding event handler.

See Also

| | | |

Was this topic helpful?