Coding a "Are you sure you want to exit?" prompt when exiting app GUI

조회 수: 19 (최근 30일)
I have coded an app for the first time which loads an image and allows you to adjust the colors and contrast. I would like to add a feature that when I press the "Exit" button, the app will ask the user "Are you sure you want to exit?" with two buttons "yes" or "no"
Right now I have a callback funtion called ExitPressed which runs app.delete();. I am assuming that what I have to code would be some function that checks if "yes" or "no" is pressed and then runs app.delete() is yes is pressed.
I am not sure how to get a window to pop up after the user presses Exit.
I appreciate any help possible.Thank you,

채택된 답변

Riccardo Scorretti
Riccardo Scorretti 2022년 4월 30일
You could modify the code of callback ExitPressed more or less in this way:
answer = questdlg('Are you sure you want to exit?', 'Confirm action', 'Yes', 'No', 'No');
if strcmpi(answer, 'Yes')
app.delete();
else
% Just do nothing
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by