Specifications

5 Application Examples
5-14
Specify the Location of the Dialog
The dialog M-file accepts an input argument that specifies where to display the
dialog. This enables the
Close button callback to locate the dialog with respect
to the main application window. The argument is a two-element vector
containing the left and bottom offsets from the right and lower edge of the
screen, in character units. The
Close button callback determines these values.
Preventing Figure Flash
In some cases, repositioning the dialog’s figure may cause it to “flash” on the
screen in its current position before the
set command repositions it. To prevent
this effect, save the dialog with its figure
Visible property set to off. You can
then set the
Visible property to on after specifying the position. Note that you
must specify the
Position property before setting the visibility to on.
if nargin == 1
pos_size = get(fig,'Position');
pos = varargin{1};
if length(pos) ~= 2
error('Input argument must be a 2-element vector')
end
new_pos = [pos(1) pos(2) pos_size(3) pos_size(4)];
set(fig,'Position',new_pos,'Visible','on')
end
Wait for User Response
uiwait causes modaldlg to wait before returning execution to the Close button
callback. During this time, the dialog’s callbacks can execute in response to
user action.
uiwait waits until the dialog figure is deleted or a uiresume executes. This can
be caused when:
The user clicks the
X in the close box on the window border. If this happens,
uiwait returns. Since the handle stored in the variable fig no longer
corresponds to a figure,
modaldlg uses an ishandle test to return 'cancel'
to the
Close button callback.
The
Yes button callback executes uiresume after setting handles.answer to
'yes'.