App Designer - confirm exit when application is closed from Windows bar
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi guys,
I have a simple question regarding App Designer.
Sometimes I accidentally click the close button which exits the application (obviously). Is there a way to implement the confirmation dialog?
Accepted Answer
Adam Danz
on 12 Sep 2020
Edited: Stefanie Schwarz
on 30 Jan 2024
Add a close request function to your app that requires confirmation.
1. From AppDesigner > Design View, right click the figure background, go down to "Callbacks", and select "Add CloseRequestFcn function callback".

2. A UIFigureCloseRequest() function will be added in Code View. Add this to the function where app.UIFigure is the handle to your app figure.
YN = uiconfirm(app.UIFigure,'Do you want to close the app?', 'Close request');
if strcmpi(YN,'OK')
delete(app)
end

11 Comments
Mario Malic
on 12 Sep 2020
Works great, I have not seen this "almost hidden" menu before.
Thank you Adam!
You can also access the figure's callback functions by clicking on the figure handle in the Component Browser and then click "callbacks" in the lower half of the panel on the right.

Mario Malic
on 12 Sep 2020
Edited: Mario Malic
on 12 Sep 2020
I didn't use callbacks for the figure before,and I didn't even know that they exist. Thanks for the hint.
Adam Danz
on 12 Sep 2020
Glad I could help!
Chirag
on 7 Jan 2023
@Adam Danz Thanks a lot for this Answer. It helped me too.
Adam Danz
on 8 Jan 2023
Arash Razi
on 1 Aug 2023
Nice,good job.
dpb
on 26 Apr 2025
That's a help, indeed, but is there a way to disable the window 'Close' "X" (and Alt-F4) programmatically to prevent the user from doing so while the app is busy doing something that could result in files left open, etc., ...? Can (and do) disable the programmed "Quit" button when beginning processing and then reenable it when done, but would be agoodthing™ to be able to short-circuit an accidental attempt otherwise, because they could still respond 'Yes' to the prompt...although I guess one could test a status flag in the callback function and refuse is that were set...
Image Analyst
on 26 Apr 2025
Edited: Image Analyst
on 26 Apr 2025
@dpb what if you added the close request callback and simply had it return without doing anything
return; % Bail out without closing.
I don't think it would get rid of the little x in the upper right of the title bar though. However, if you set the 'WindowState' property of the figure to 'fullscreen', it should not have a title bar and should cover up the task bar at the bottom.
app.UIFigure.WindowState = 'fullscreen';
dpb
on 26 Apr 2025
Yeah, @Image Analyst, that's what I've done for the moment with further amplification in the other thread on the callbacks in the particular app being confounded by my prior actions, not knowing better at the time...
Adam Danz
on 29 Apr 2025
This was such a great question that I wrote an article about it this morning.
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)