MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Manual do Utilizador Página 223

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 330
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 222
Sharing Data Among a GUI’s Callbacks
9-11
% Retrieve and increment the error count.
slider_data = getappdata(handles.figure1,'slider');
slider_data.number_errors = slider_data.number_errors+1;
% Save the changes.
setappdata(handles.figure1,'slider',slider_data);
% Display new total.
set(hObject,'String',...
['You have entered an invalid entry ',...
num2str(slider_data.number_errors),' times.']);
end
UserData Property
Every GUI component, and the figure itself, has a UserData property that you
can use to store application defined data. To access
UserData, a callback must
know the handle of the component with which it is associated.
Use the
get function to retrieve UserData, and the set function to set it.
UserData Property Example: Passing Data Between a Slider and an Edit
Text Box
A previous topic, “GUI Data Example: Passing Data Between a Slider and an
Edit Text Box” on page 9-7, used GUI data to initialize and maintain an error
counter. This example shows you how to do the same thing using the
UserData
property of the edit text box to store the error count. Refer to the GUI data
example for details of the example.
1 Initialize the edit text UserData property in the opening function. Add the
following code to the opening function. This code initializes the data in a
structure to allow for other data that may be needed.
number_errors = 0;
set(handles.edit1,'UserData',number_errors)
Note Alternatively, you could add a CreateFcn callback for the edit text to
the M-file, and initialize the error counter there.
Vista de página 222
1 2 ... 218 219 220 221 222 223 224 225 226 227 228 ... 329 330

Comentários a estes Manuais

Sem comentários