MATLAB Creating Graphical User Interfaces

(Barry) #1
Modal Dialog Box in GUIDE

3 Click Yes or No.



  • Yes closes both dialog boxes.

  • No closes just the Confirm Close dialog box.


How Close Confirmation Dialogs Work


This section describes how the dialogs work:


1 When you click the Close button, the close_pushbutton_Callback performs
these tasks:


a Gets the current position of the window from the handles structure with the
command:

pos_size = get(handles.figure1,'Position')
b Calls the modal dialog box with the command:

user_response = modaldlg('Title','Confirm Close');

TipThis is an example of calling a UI with a property value pair. In this case,
the figure property is 'Title', and its value is the string 'Confirm Close'.
Opening modaldlg with this syntax displays the text “Confirm Close” at the top
of the dialog box.

2 The modal dialog box opens with the 'Position' obtained from the code that calls
it.


3 The opening function in the modal modaldlg code file:



  • Makes the dialog box modal.

  • Executes the uiwait command, which causes the dialog box to wait for you to
    click Yes or No, or click the close button (X) on the window border.


4 When you click one of the two push buttons, the callback for the push button:



  • Updates the output field in the handles structure.

  • Executes uiresume to return control to the opening function where uiwait is
    called.


5 The output function is called, which returns the string Yes or No as an output
argument, and deletes the dialog box with the command:

Free download pdf