Reputation: 157
I want to disable close button of figure in Matlab.
How can I do that?
Upvotes: 1
Views: 2289
Reputation: 11
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
Upvotes: 1
Reputation: 16224
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');
Upvotes: 1