필터 지우기
필터 지우기

uiwait(msgbox("My message") dialog comes up behind the app. User never sees it.

조회 수: 13 (최근 30일)
Gavin
Gavin 2024년 7월 29일
댓글: Gavin 2024년 9월 23일 18:22
Why does uiwait(msgbox("My message") dialog come up behind the app? My user never sees it so can't click OK. Is there a way to bring it to the front other than uialert() which is a lot more complex to program?

채택된 답변

Avni Agrawal
Avni Agrawal 2024년 7월 30일
Hi @Gavin,
I understand that the `msgbox` function can sometimes create a message box that appears behind the main app window, making it difficult for users to see and interact with it. To ensure that the message box appears in front of the app, you can use the `figure` function to bring the message box to the front.
Here's a simple way to ensure that the message box appears in front:
h = msgbox('My message');
figure(h);
uiwait(h);
This code snippet creates the message box and then brings it to the front using the `figure` function. The `uiwait` function will still block the execution until the user clicks OK.
Alternatively, if you want a more robust solution, you can use the `WindowStyle` property of the message box to make it modal, which ensures that the message box stays on top of the app until the user interacts with it:
h = msgbox('My message', 'Title', 'modal');
uiwait(h);
By setting the `WindowStyle` to `'modal'`, you make sure that the message box remains in front of the app window and requires the user to interact with it before proceeding.
Both of these methods should help ensure that your message box is visible to the user and can be interacted with appropriately.
I hope this helps!
  댓글 수: 1
Gavin
Gavin 2024년 9월 23일 18:22
Great help. Sorry for such a late reply. I switched to uialert and uiconfirm in my app but this answer can be useful I hope for others and for MyDir = uigetdir(path,title) which pops up wherever it feels like!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mario Malic
Mario Malic 2024년 7월 29일
편집: Mario Malic 2024년 7월 29일
Hi again,
I don't know if there is a better solution, but here is an example with uialert
Idea is to create a new figure with it, and once the button is pressed the figure will be deleted.
fig = uifigure();
% fig = uifigure("WindowStyle", "modal"); % Maybe this works better
uialert(fig,"File not found.","Invalid File", "CloseFcn", @(src, evt)delete(src));
while ishandle(fig) % wait for figure to be deleted
pause(0.1);
end
% rest of code
In case the figure shows behind the active window, try focus function, or
uifigure(fig);
Cheers

카테고리

Help CenterFile Exchange에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by