Click here to Skip to main content
15,885,309 members
Articles / General Programming
Tip/Trick

Control resize

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
14 Jul 2010CPOL 8.5K   1  
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
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)


Written By
Software Developer
United States United States
Writing code for 00100010 years.

Comments and Discussions

 
-- There are no messages in this forum --