Close uialert - App designer

In App designer I have a function called
DayButtonPushed(app, event)
With the following code:
aFig = uifigure;
message = sprintf('March \n\nYear 2022');
uialert(aFig,message,'Info','Icon','info');
When I press the OK it does not close the background window. Therefore, how can I close all upon pressing ok (image attached)?

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 10 日

1 投票

Why create a uifigure() there? uialert() will create its own uifigure()

6 件のコメント

Ali razi
Ali razi 2022 年 3 月 10 日
This is what I see in the examples at https://www.mathworks.com/help/matlab/ref/uialert.html
Is their another way to solve it?
Walter Roberson
Walter Roberson 2022 年 3 月 10 日
Ah, I see.
It is a modal alert, so it will not return until the user has clicked. So after the uialert() call you can destroy the figure.
Ali razi
Ali razi 2022 年 3 月 11 日
if I add close(aFig); it automaticly close. Any idea how to solve it?
Walter Roberson
Walter Roberson 2022 年 3 月 11 日
I see what you mean.
I had a look in the source code, but the graphics works a completely different way for uifigure() and in the time I was willing to spend, I did not find a method.
Simon Chan
Simon Chan 2022 年 3 月 12 日
Add a CloseFcn may be a workaround if you don't want to use the uifigure anymore.
aFig = uifigure;
message = sprintf('March \n\nYear 2022');
uialert(aFig,message,'Info','Icon','info','CloseFcn',{@closefig,aFig});
function closefig(src,event,aFig)
delete(aFig)
end
Walter Roberson
Walter Roberson 2022 年 3 月 12 日
@Simon Chan That's a good idea.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Programmatically についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 3 月 10 日

コメント済み:

2022 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by