Creating Graphical User Interfaces |
|
Setting Up the GUI with the Close Button
To set up the second GUI with a Close button, do the following:
- Select New from the File menu in the GUIDE Layout Editor.
- In the GUIDE Quick Start dialog, select Blank GUI (Default) and click OK. This opens the blank GUI in a new Layout Editor window.
- Drag a push button from the Component palette of the Layout Editor into the layout area.
- Right-click the push button and select Property Inspector from the pop-up menu.
- Change the
String
property to Close
.
- Change the
Tag
property to close_pushbutton
.
- Click the M-file editor icon on the toolbar of the Layout Editor.
- Click the callback icon on the toolbar of the M-file editor and select
close_pushbutton_Callback
from the menu.
- The following generated code for the close button callback should appear in the M-file 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)
- After these comments, add the following code:
% Get the current position of the GUI 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 GUI application window
% .
% .
% .
delete(handles.figure1)
end
| Setting Up the Close Confirmation Dialog | | Running the GUI with the Close Button | |
© 1994-2005 The MathWorks, Inc.