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

19 visualizaciones (últimos 30 días)
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,

Respuesta aceptada

Riccardo Scorretti
Riccardo Scorretti el 30 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by