I want to disable close button of figure in Matlab. How can I do that?
1
votes
3 Answers
1
votes
Seems like you have to override the CloseRequestFcn
event handler, see here. You can't hide or disable the close button, but you can ensure that user clicking on it won't have any effect.
1
votes
With this you can disable all:
set( findall(handles.your_uipanel, '-property', 'Enable'), 'Enable', 'off')
but to only disable the close one:
function closeRequestDemo
figHdl = dialog('Name','Close Request Demo',...
'CloseRequestFcn',@cmdClose_Callback);...dialog creates a nice stripped down figure
uicontrol('Parent',figHdl,...
'String','Close',...
'Callback',@cmdClose_Callback);
function cmdClose_Callback(hObject,varargin)
disp(['Close Request coming from: ',get(hObject,'Type')]);
%do cleanup here
delete(figHdl);
end %cmdClose_Callback
end %closeRequestDemo
Sources here https://www.mathworks.com/matlabcentral/newsreader/view_thread/290049
another way is:
% Get all the handles to everything we want to set in a single array.
handleArray = [handles.editText, handles.pushbutton, handles.listbox];
% Set them all disabled.
set(handlesArray, 'Enable', 'off');
1
votes
You can replace its function by typing:
set(fig_obj,'CloseRequestFcn','code to execute')
on my example I replace it by:
set(fig_obj,'CloseRequestFcn','set(fig_obj,"Visible","off");');
You can find more about here:
https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html#buiwuyk-1-CloseRequestFcn