Size a Form’s Controls to Match the Form’s Size
Problem
Windows users have become accustomed to resizing forms on their screens. A professional-looking application will proportionally resize the controls on a form when you stretch or shrink that form. You’d like to be able to resize your forms while the application is running and have the controls on the form react appropriately. For example, the Database Explorer window’s list box expands when you expand the window. How can you do this on your own forms?
Solution
Because Access can notify your application when the user resizes a form, you can attach code to the Resize form event and react to the change in size. Access also triggers this event when it first draws the form, so you can place your controls correctly then, too. Base your calculations on the form’s InsideWidth and InsideHeight properties.
Load and run the form
frmExpando in 02-07.MDB
. Resize the form and
watch the size of the large text box. Also notice the positions of
the two command buttons. Figure 2-13 shows the form
in design mode, and Figure 2-14 shows two copies of
the form sized to different proportions. Though it’s perfectly
reasonable to change the size of all the controls, this form does
not. It uses three different techniques:
- Do nothing
The label above the text box doesn’t change at all as you resize the form.
- Change position only
The two command buttons move with the right edge of the form, but they don’t change size.
- Change size
The large text box changes ...
Get Access Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.