Creating Graphical User Interfaces    

Protecting the GUI with a Close Request Function

Whenever a user closes a figure, MATLAB first executes the figure's close request function, as defined by the CloseRequestFcn figure property. The default close request function simply deletes the figure. However, a GUI may want to protect the user from unintentionally deleting a figure if they click on the X in the close box of the window border.You can change the default close request function by redefining the figure's CloseRequesFcn.

The The Close Button Callback section shows a callback for the GUI's Close button that you could also use as a close request function. To add the new close request function to your application M-file, select the figure in the Layout Editor and right click to display the context menu.

Select Edit CloseRequestFcn from the context menu. GUIDE automatically places a new subfunction in the application M-file for the GUI and changes the figure's CloseRequesFcn property to execute this subfunction as the close request function.

The Redefined Close Request Function

The GUIs close request function simply calls the Close button's callback.


 Defining the Yes and No Buttons Callbacks List Box Directory Reader