Specifications
5 GUI Applications
5-44
The size of the Contact Name text box changes in proportion to the new figure
width. This is accomplished by:
• Changing the
Units of the text box to normalized.
• Resetting the width of the text box to be 78.9% of the figure’s width.
• Returning the
Units to characters.
If the new width is less than the original width, use the original width.
Changing the Height
If the user attempts to change the height, use the original height. However,
because the resize function is triggered when the user releases the mouse
button after changing the size, the resize function cannot always determine the
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 minus
the 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 releases the mouse.
When the GUI is first run, 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 ResizeFcn(hObject, eventdata, handles)
% Get the figure size and position
Figure_Size = get(hObject, '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))