Creating Graphical User Interfaces    

The Address Book Resize Function

The address book defines its own resize function. To use this resize function, you must set the Application Options dialog Resize behavior to User-specified, which in turn sets the figure's ResizeFcn property to:

Whenever the user resizes the figure, MATLAB calls the ResizeFcn subfunction in the address book M-file (address_book.m)

Behavior of the Resize Function

The resize function allows users to make the figure wider, to accommodate long names and numbers, but does not allow the figure to be made narrower than its original width. Also, users cannot change the height. These restrictions do not limit the usefulness of the GUI and simplify the resize function, which must maintain the proper proportions between the figure size and the components in the GUI.

When the user resizes the figure and releases the mouse, the resize function executes. At that point, the resized figure's dimensions are saved. The following sections describe how the resize function handles the various possibilities.

Changing the Width

If the new width is greater than the original width, set the figure to the new width.

The size of the Contact Name text box changes in proportion to the new figure width. This is accomplished by:

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:

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


 Saving Changes to the Address Book from the Menu