For controls, register handler functions either at the time
you create an instance of the control (using actxcontrol
),
or any time afterward (using registerevent
).
For servers, use registerevent
to register
events.
Use events
to list all
the events a COM object recognizes.
When a registered event is triggered, MATLAB® passes information from the event to its handler function, as shown in the following table.
Arguments Passed by MATLAB Functions
Arg. No. | Contents | Format |
---|---|---|
| Object name | MATLAB |
| Event ID |
|
| Start of Event Argument List | As passed by the control |
| End of Event Argument List (Argument N) | As passed by the control |
| Event Structure |
|
| Event Name |
|
When writing an event handler function, use the Event Name argument
to identify the source of the event. Get the arguments passed by the
control from the Event Argument List (arguments 3
through end-2
).
All event handlers must accept a variable number of arguments:
function event (varargin) if (strcmp(varargin{end}, 'MouseDown')) % Check the event name x_pos = varargin{5}; % Read 5th Event Argument y_pos = varargin{6}; % Read 6th Event Argument end
Note: The values passed vary with the particular event and control being used. |
The Event Structure argument passed by MATLAB contains the fields shown in the following table.
Fields of the Event Structure
Field Name | Description | Format |
---|---|---|
| Event Name |
|
| Control Name | MATLAB |
| Event Identifier |
|
| Event Arg Value 1 | As passed by the control |
| Event Arg Value 2 | As passed by the control |
etc. | Event Arg N | As passed by the control |
For example, when the MouseDown
event of
the mwsamp2
control is triggered, MATLAB passes
this Event Structure to the registered event handler:
Type: 'MouseDown' Source: [1x1 COM.mwsamp.mwsampctrl.2] EventID: -605 Button: 1 Shift: 0 x: 27 y: 24
actxcontrol
| events
| registerevent