uiwait(msgbox("My message") dialog comes up behind the app. User never sees it.
6 次查看(过去 30 天)
显示 更早的评论
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
2024-7-30
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 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Maintain or Transition figure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!