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)?

35 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by