Specifications
4 Programming GUIs
4-20
from the View menu. This displays the Property Inspector, as shown in the
following figure.
The ActiveX control
mwsamp has just two properties:
•
Label, which contains the text that appears at the top of the control
•
Radius, the default radius of the circle, which is 20
The example in the next section shows how to program the GUI to
• Change the radius when a user clicks the circle
• Change the label to display the new radius
Adding a Callback to an ActiveX Control to Change a Property
To change a property of the control when a user performs an action, you need
to add a callback to an ActiveX control. For example, to make
mwsamp decrease
the radius of the circle by 10 percent and display the new value each time a
user clicks the ActiveX control, you can add an event, or callback, corresponding
to the click action. To do so,
1 Right-click the ActiveX control in the Layout Editor to bring up its context
menu.
2 In the context menu, place the cursor over View Callbacks and select Click.
This creates a callback called
activex1_Click and opens the GUI M-file
with the first line of the callback highlighted.
3 Add the following commands to the activex1_Click callback:
hObject.radius = .9*hObject.radius;
hObject.label = ['Radius = ' num2str(hObject.radius)];