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