Create non-visible message dialog box
3 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Bora Eryilmaz
on 31 Jan 2023
Edited: Bora Eryilmaz
on 31 Jan 2023
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
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!