How do I disable the Close button at the top right corner of figure window and the Close option in the title bar menu in MATLAB 7.6 (R2008a)?

32 views (last 30 days)
I want to disable the Close button on the upper left corner of a figure window and the Close menu item in the Title bar menu in a GUI application.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Jan 2010
In MATLAB 7.6 (R2008a), the Close button on the upper left corner of a figure window and the Close menu item in the Title bar menu in a GUI application can be disabled by implementing a custom CloseRequestFcn in your GUI. To edit this function, right click on the Figure window in design mode and under the Callback functions portion select the CloseRequestFcn to include this function in the corresponding program file.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
commenting the following line will prevent the CloseRequestFcn from deleting the figure when a user clicks on the Close button or uses the Close menu item.
delete(hObject)
Please note that with the above setting you have to use the following command to forcefully close the window:
close force

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!