Re-Sizing Forms

Normally, when you re-size a form, the objects on that form stay where they are. Most users would prefer that they re-size and/or re-position themselves in some logical manner.

Visual Basic | Delphi | C++ Builder | Java | Windows API

Visual Basic 6.0

ResizeControls.bas contains routines to control the location of (pin) UI Objects when a form is re-sized. Normally, objects always keep the same distance from the top and left. These routines allow you to keep a fixed number of pixcels from the bottom or right. In addition, some objects can be stretched so that the right edge keeps a constant distance from the right hand edge, or so that the bottom edge keeps a constant distance from the bottom of the form. These are controlled via the following constants.


Technique Based on "object.move"

An alternate way to do this (which uses much less code) is used in a BoonDog example. Search the listings for Form_Resize(). (I don't know exactly what the variable ScaleWidth refers to.)

Basically, this code uses object.move to re-size the objects.


Delphi

In Delphi, these options are trivial. All components are derived from TControl which provides

Some components publish all 3 properties (ie, make them available at design time), others don't. For instance

If the control is Anchored to opposite sides (left and right or top and bottom) then the control will stretch when the form is re-sized.

The align property controls both position and size.

When you want to keep a bunch of related objects (usually buttons) centered, you simply place them in a container and then center the container.

On the negative side, once you've set these parameters, they are active (functional) at design time. Thus, any attempt to re-size a form while it is being designed will make the controls stretch and move.

Also, if the form is made narrow enough to display a horitoztal scroll bar, then the TRichEdit control with verticle stretching enabled will not display correctly.


C++ Builder

Same as Delphi.


Java


Windows API

Not applicable.
Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / ResizeForm.htm