Specifications
An Address Book Reader
5-53
original position of the GUI on screen. Therefore, the resize function applies a
compensation to the vertical position (second element in the figure
Position
vector) as follows:
vertical position when mouse released
+ height when mouse released –
original height
When the figure is resized from the bottom, it stays in the same position. When
resized from the top, the figure moves to the location where the mouse button
is released.
Ensuring the Resized Figure is On Screen
The resize function calls movegui to ensure that the resized figure is on screen
regardless of where the user release the mouse.
When the GUI is first launched, it is displayed at the size and location specified
by the figure
Position property. You can set this property with the Property
Inspector when you create the GUI.
Code Listing
function varargout = ResizeFcn(h, eventdata, handles, varargin)
% Get the figure size and position
Figure_Size = get(h,'Position');
% Set the figure's original size in character units
Original_Size = [ 0 0 94 19.230769230769234];
% If the resized figure is smaller than the
% original figure size then compensate
if (Figure_Size(3)<Original_Size(3)) | (Figure_Size(4) ~= Original_Size(4))
if Figure_Size(3) < Original_Size(3)
% If the width is too small then reset to origianl width
set(h,'Position',...
[Figure_Size(1) Figure_Size(2) Original_Size(3) Original_Size(4)])
Figure_Size = get(h,'Position');
end
if Figure_Size(4) ~= Original_Size(4)
% Do not allow the height to change
set(h,'Position',...
[Figure_Size(1), Figure_Size(2)+Figure_Size(4)-Original_Size(4),...
Figure_Size(3), Original_Size(4)])
end
end