from
MakeDialog
by Richard Medlock
Creates a simple dialog using system colours.
|
| MakeDialog(varargin)
|
function hFig = MakeDialog(varargin)
% [hFig] = MAKEDIALOG(DIMENSIONS,TITLE,TAG)
%
% Function to create a screen-centred dialog box with the specified dimensions.
%
% DIMENSIONS - specified in Pixels as [Width Height]
%
% TITLE - String containing the text to appear in the Figure's title bar.
%
% TAG - Unique string identifier
%
%
% If no arguments are specified, a dialog box 300 x 200 will be created.
%
%
% Copyright (c) 2001 Richard Medlock.
% ---------------------------------------------------------------------------
% Do a bit of error checking to make sure we have all the right info...
% ---------------------------------------------------------------------------
if nargin == 0
%If no arguments, use defaults...
dimensions = [300 200];
title = 'Dialog Box';
tag = 'DlgBox';
elseif nargin == 1
%Make sure user specified 2 values...
if length(varargin{1}) == 2
dimensions = varargin{1};
else
error('Please specify the dimensions as [Width Height]');
end
% Use default title & tag...
title = 'Dialog Box';
tag = 'DlgBox';
elseif nargin == 2
% Make sure user specified 2 values...
if length(varargin{1}) == 2
dimensions = varargin{1};
else
error('Please specify the dimensions as [Width Height]');
end
title = varargin{2};
% Use default tag...
tag = 'DlgBox';
else
% Make sure user specified 2 values...
if length(varargin{1}) == 2
dimensions = varargin{1};
else
error('Please specify the dimensions as [Width Height]');
end
% Use the user specifed values...
title = varargin{2};
tag = varargin{3};
end
% ---------------------------------------------------------------------------
% Create the dialog
% ---------------------------------------------------------------------------
% Set the Dimensions of the dialog box...
DialogWidth = dimensions(1);
DialogHeight = dimensions(2);
% Position the Dialog in the centre of the screen...
ScreenSize = get(0,'ScreenSize');
WindowX = (ScreenSize(3)/2) - (DialogWidth/2);
WindowY = (ScreenSize(4)/2) - (DialogHeight/2);
% Size the figure in pixels:
hFig = figure('Units','Pixels','Position',[WindowX WindowY DialogWidth DialogHeight]);
% Hide the built-in menu bar:
set(hFig,'MenuBar','none');
% User System Colors for the figure's background...
set(hFig,'Color',get(0,'DefaultUicontrolBackgroundColor'));
% Give the figure a title: (hide the default number title)
set(hFig,'Name',title);
set(hFig,'NumberTitle','off');
set(hFig,'Tag',tag);
set(hFig,'Resize','off');
|
|
Contact us at files@mathworks.com