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

27 visualizzazioni (ultimi 30 giorni)
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,

Risposta accettata

Riccardo Scorretti
Riccardo Scorretti il 30 Apr 2022
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

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by