User`s guide
Add Code for Components in C allbacks
Programming a User Interface Control to Update an ActiveX
Control
This topic continues the previous example by adding a slider to the GUI and
programming the slider to change the circle radius. This example must also
update the slider if the user clicks the circle.
1 Add a slider to your layout and then add the following code to the slider1
Callback callback:
handles.activex1.radius = ...
get(hObject,'Value')*handles.default_r adius;
handles.activex1.label = ...
['Radius = ' num2str(handles.activ ex1.radius)];
refresh(handles.figure1);
The first command
• Gets the
Value of the slider, which in this example is a number between
0 and 1, the default values of the slider’s
Min and Max properties.
• Sets
handles.activex1.radius equal to the Value times the default
radius.
2 In the opening function, add the default radius to the hand les structure.
The
activex1_Click callback uses the default radius to update the slider
value if the user clicks the circle.
handles.default_radius = handles.a ctivex1.radius;
3 In the activex1_Click callback, reset the slider’s Value each time the user
clicks the circle in the ActiveX control. The following command causes the
slider to change position corresponding to the new value of the radius.
set(handles.slider1,'Value',...
hObject.radius/handles.default_radius) ;
When you open the GUI and move the slider by clicking and dragging, the
radius changes to a new value betw een 0 and the default radius of 20, as
shown in the following figure.
8-55