Masoud Zayyani
Masoud Zayyani

Reputation: 157

How to disable close button on figure

I want to disable close button of figure in Matlab. enter image description here How can I do that?

Upvotes: 1

Views: 2289

Answers (3)

Victor
Victor

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

developer_hatch
developer_hatch

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

randomir
randomir

Reputation: 18697

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.

Upvotes: 1

Related Questions