Create non-visible message dialog box

2 ビュー (過去 30 日間)
Andrés Aguilar
Andrés Aguilar 2023 年 1 月 31 日
編集済み: Andrés Aguilar 2023 年 2 月 2 日
Hi!
I am coding part of a project (old enough to be based on GUIDE) and I need to present the user with some message dialog boxes.
These dialogs use custom icons and change depending on a sensor readout which is updated continuously inside a while loop until the user presses OK in one of the dialogs.
I already tried two aproaches:
1- Creating a single dialog, store the figure object and then updating its properties to change the icon, the string and some others.
2 -Creating different dialogs, storing them and then changing their visibility rather than updating some properties.
Neither of these satisfied me completely because in aproach #1, when updating properties (specially the icon) the result (particularly in deployed mode) takes rather long to update and results confusing to users and aesthetically sub-optimal.
Approach #2 instead is faster in changing from one dialog to another (with icon and strings already setup) as the sensor readout changes but when I create every dialog (four of them) they come into focus and are displayed briefly (longer if isdeployed is true) before setting Visible = 'off' (in the very next line) to all but one and then setting Visible = 'on to the corresponding dialog as the readout of the sensor changes. This is better but still not optimal.
So, my question is:
Is there an elegant way of creating a message dialog box that has is Visible property set to 'off'? I noticed the msgbox.m file sets this property to 'on' on line 390. It would be nice to have the ability to specify this property during creation.
By elegant, I mean pure matlab, because this project is going to be run in deployed mode and developed and maintained by different people so using third party solutions is not the best option for me.
I really appreciate your time and help!

回答 (1 件)

Bora Eryilmaz
Bora Eryilmaz 2023 年 1 月 31 日
編集済み: Bora Eryilmaz 2023 年 1 月 31 日
One option is to not create all four dialog at once. Just create the dialog that needs to be visible at the time and store its handle for later use. This way, you will eventually create all four dialogs, but they will be first created when needed and become visible at the time. You could implement a logic like this:
function test()
persistent dlg1
persistent dlg2
persistent dlg3
persistent dlg4;
dialog_number = 1; % Put your logic here to decide which dialog is needed
switch dialog_number
case 1
if isempty(dlg1)
% Create the dialog 1 here
dlg1 = ...
end
dlg1.Visible = 'on'
case 2
% Repeat for dlg2
case 3
% Repeat for dlg3
case 4
% Repeat for dlg4
end
end
  1 件のコメント
Andrés Aguilar
Andrés Aguilar 2023 年 2 月 2 日
Bora, thank you very much for your answer. This would indeed be better as it would only take longer the first time the dialogs need to be shown.
I forgot to explain that this would go inside a while loop, it would look something like this:
while true
dialog_number = MyLogic(args);
switch dialog_number
case 1
%
case 2
if ~isempty(dlg1)
dlg1.Visible = 'off'
end
if isempty(dlg2)
% Create the dialog 2 here
dlg2 = msgbox('Hello World')
end
if ~isempty(dlg3)
dlg3.Visible = 'off'
end
if ~isempty(dlg4)
dlg4.Visible = 'off'
end
case 3
%
case 4
end
end

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by