GUI Warning before closed

조회 수: 7 (최근 30일)
Valentino
Valentino 2015년 6월 7일
댓글: Crish 2021년 1월 16일
Hello,
would like to have a warning ( " Data saved yes no") before my GUI (made with guide) is closed. I can't figure out where to put that code. Must be something in the closing function made automatically by the GUI guide??
Thank you

채택된 답변

Valentino
Valentino 2015년 8월 6일
편집: Valentino 2015년 8월 6일
My solution: write this in the second function written by guide (my_gui_OpeningFcn):
set(handles.figure1,'CloseRequestFcn',@closeGUI;
Then write an extra function like this:
function closeGUI(hObject, eventdata, handles)
selection = questdlg(Close MyGUI?', ...
'Warning', ...
'Yes','No','Yes');
switch selection
case 'Yes'
delete(gcf)
case 'No'
return
end

추가 답변 (2개)

Image Analyst
Image Analyst 2015년 6월 7일
I don't think the closing function or output function will always be executed, especially if they click on the X in the title bar. To make sure your code get executed even if they try to close the window by clicking on the x in the title bar, you need to put your code into the figMainWindow_CloseRequestFcn() function.
  댓글 수: 1
Valentino
Valentino 2015년 6월 15일
편집: Valentino 2015년 6월 15일
Thank you for your answer.I'm unterstanding tis correct, i have to write a new function figmy_own_GUI_CloseRequestFcn()? How do i call the function?
if true
function figmy_own_GUI_CloseRequestFcn(hObject, eventdata, handles)
warndlg('Pressing OK will clear memory','!! Warning !!')
end

댓글을 달려면 로그인하십시오.


Maha
Maha 2020년 1월 28일
Having the same issue. I unfortunately close figures and my GUI at the same time quite often without paying attention.
Any chance to get a warning when we try to close Matlab ? Like some other programs do with "Are you sure you want to close XXX ?"
  댓글 수: 2
Nilesh Sahu
Nilesh Sahu 2020년 9월 27일
Click on Home -> Preferences -> General -> Confirmation Dialogs -> Check on Confirm before exiting Matlab.
Crish
Crish 2021년 1월 16일
Is this also applicable in the apo designer?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by