| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
h.unregisterevent(eventhandler)
unregisterevent(h, eventhandler)
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.
Unregister events for a control:
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
MATLAB displays:
ans =
'Click' 'sampev'
'DblClick' 'sampev'
'MouseDown' 'sampev'
'Event_Args' 'sampev'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
MATLAB displays:
ans =
'Click' 'sampev'
'MouseDown' 'sampev'
'Event_Args' 'sampev'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
MATLAB displays:
ans =
'click' 'myclick'
'dblclick' 'my2click'
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
MATLAB displays:
ans =
{}
Unregister Microsoft Excel workbook events:
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.eventlistenersMATLAB shows the events with the corresponding event handlers.
ans =
'Activate' 'EvtActivateHndlr'
'Deactivate' 'EvtDeactivateHndlr'Next, unregister the Deactivate event handler:
wb.unregisterevent({'Deactivate' 'EvtDeactivateHndlr'})
wb.eventlistenersMATLAB shows the remaining registered event (Activate) with its corresponding event handler.
ans =
'Activate' 'EvtActivateHndlr'
eventlisteners | events (COM) | isevent | registerevent | unregisterallevents
![]() | unregisterallevents | untar | ![]() |

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 |