Click here to Skip to main content
11,805,266 members (62,774 online)
Click here to Skip to main content

Tagged as


Control resize

, 14 Jul 2010 CPOL 4.6K 1
Rate this:
Please Sign up or sign in to vote.
Allow controls to grow or shrink with form changes
This calculation allows automatic resizing of controls at runtime. The change in size is based on the change in size of the parent form. An example of this is a List on a form. When the form is resized, the list needs to be longer or shorter in response to the parent window size changing. Another example might be a frame whose dimensions need to change but stay proportional to the parent window.

To work, the design time dimensions are captured on the form load. When the form size is changed, the original design time dimension and the current window dimension difference are used to change a control's size.

The advantage of the equation is that there are no rounding error accumulations or proportion distortions. The control size is to keep proportional to its design time layout but can expand to fill the form at runtime.

Variables to hold the design time values:
dclfld Design_ThisForm_Height type(*integer) len(4)
dclfld Design_ThisForm_Width  type(*integer) len(4)
dclfld Design_Control_Height  type(*integer) len(4)
dclfld Design_Control_Width   type(*integer) len(4)

Initializing those variables to their values in an on load event:

BEGSR form Load
  Design_ThisForm_Height = *ThisForm.Height
  Design_ThisForm_Width  = *ThisForm.Width
  Design_Control_Height  = Control.Height
  Design_Control_Width   = Control.Width

And finally, resizing a control when a form size changes.

BEGSR form Resize
  Control.Height= ( *thisform.Height -  Design_ThisForm_Height) + Design_Control_Height
  Control.Width = ( *thisform.Width  -  Design_ThisForm_Width ) + Design_Control_Width


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
Software Developer
United States United States
Writing code for 00100010 years.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 14 Jul 2010
Article Copyright 2010 by
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid