MATLAB Creating Graphical User Interfaces

(Barry) #1

9 Examples of GUIDE UIs


The code file, closedlg.m, opens in the Editor.

On the Editor tab, in the Navigate section, click Go To, and then select
close_pushbutton_Callback.

The following generated code for the Close button callback appears in the Editor:
% --- Executes on button press in close_pushbutton.
function close_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to close_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
9 After the preceding comments, add the following:
% Get the current position from the handles structure
% to pass to the modal dialog.
pos_size = get(handles.figure1,'Position');
% Call modaldlg with the argument 'Position'.
user_response = modaldlg('Title','Confirm Close');
switch user_response
case {'No'}
% take no action
case 'Yes'
% Prepare to close application window
%.
%.
%.
delete(handles.figure1)
end
10 Save closedlg.m.

Run the Program


(^1) On the Layout Editor toolbar, click the Run button.
2 In the closedlg dialog box, click the Close push button.
The modal dialog box opens.

Free download pdf