2017-06-17 40 views

回答

1

似乎您必须重写CloseRequestFcn事件处理程序,请参阅here。您不能隐藏或禁用关闭按钮,但可以确保用户点击它不会产生任何影响。

+0

谢谢你的反应,但它没有任何解决方案。 –

+0

我该怎么做? –

+0

@MasoudZayyani,方法如下:https://www.mathworks.com/matlabcentral/answers/139854-how-to-change-the-gui-close-function-whithout-changing-the-close-function-of-figures – randomir

1

有了这个,你可以禁用所有:

set(findall(handles.your_uipanel, '-property', 'Enable'), 'Enable', 'off') 

但只禁用接近一个:这里

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 

来源https://www.mathworks.com/matlabcentral/newsreader/view_thread/290049

另一种方式是:

% 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'); 
+0

谢谢,但我应该在哪里插入第一个代码?在** CloseRequestFcn **? –

+0

@MasoudZayyani不完全,我会添加另一个选择,你可以在这里查看:https://www.mathworks.com/matlabcentral/answers/72650-hide-and-disable-uicontrols-in-groups你不会插入它,你执行它。 –

+0

@MasoudZayyani我更新了答案,我希望能帮助你,别忘了接受答案,如果有帮助的话:) –