Click here to Skip to main content
Click here to Skip to main content

Control resize

By , 14 Jul 2010
Rate this:
Please Sign up or sign in to vote.
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
Endsr
 
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
Endsr

License

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

About the Author

Weberto.com
Software Developer
United States United States
Writing code for 00100010 years.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 14 Jul 2010
Article Copyright 2010 by Weberto.com
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid