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

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

Respuesta aceptada

Avni Agrawal
Avni Agrawal el 30 de Jul. de 2024
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 comentario
Gavin
Gavin el 23 de Sept. de 2024
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!

Iniciar sesión para comentar.

Más respuestas (1)

Mario Malic
Mario Malic el 29 de Jul. de 2024
Editada: Mario Malic el 29 de Jul. de 2024
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

Categorías

Más información sobre Maintain or Transition figure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by