1. Home
  2. Computing & Technology
  3. Delphi Programming

Multi-Resolution Delphi Apps
Anchors, Alignement and Constraints; Third party VCL

By Zarko Gajic, About.com

Once you know what issues to bear in mind when scaling Delphi forms on different screen resolutions ... you are ready for some coding...

When working with Delphi version 4 (or above) several properties are designed to help us maintain the look and layout of controls on a form.

Use Align to align a control to the top, bottom, left, or right of a form or panel and have it remain there even if the size of the form, panel, or component that contains the control changes. When the parent is resized, an aligned control also resizes so that it continues to span the top, bottom, left, or right edge of the parent.

Use Constraints to specify the minimum and maximum width and height of the control. When Constraints contains maximum or minimum values, the control can’t be resized to violate those constraints.

Use Anchors to ensure that a control maintains its current position relative to an edge of its parent, even if the parent is resized. When its parent is resized, the control holds its position relative to the edges to which it is anchored. If a control is anchored to opposite edges of its parent, the control stretches when its parent is resized.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure ScaleForm
    (F: TForm; ScreenWidth, ScreenHeight: LongInt) ;
begin
   F.Scaled := True;
   F.AutoScroll := False;
   F.Position := poScreenCenter;
   F.Font.Name := 'Arial';
   if (Screen.Width <> ScreenWidth) then begin
     F.Height :=
         LongInt(F.Height) * LongInt(Screen.Height)
         div ScreenHeight;
     F.Width :=
         LongInt(F.Width) * LongInt(Screen.Width)
         div ScreenWidth;
     F.ScaleBy(Screen.Width,ScreenWidth) ;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

VCL

And finally, why bother with coding when there are components for all your resizing problems (try them and choose the best one for you):

  • TNFormSizing
    Need forms that keep proportionality when being resized manually? And also when being Maximized or Tiled/Cascaded? Forms for both MDI and SDI type applications? TNFormSizing is all you need for that. Just put the TNFormSizing on your form and choose an option for ProportionType - its only published property. Free with code.

  • TFormResizer
    To use this free component (+ source code), just drop it onto a form and then add one line of code apiece to the form's OnCreate and OnResize handlers (optionally resizes the fonts of the components).

  • Resizer component
    Another free component. Includes component editor with all controls for this container in table format. Then you can define the behavior for each control. All settings will be stored in DFM file automatically.

  • GTSizer
    Shareware component: resizes at design time, automatic resolution independence, supports third party/custom controls, supports all border styles, etc.

  • Perfect Size
    All you do is drop PerfectSize on a form and the rest is handled for you! At run time, your controls and fonts are always kept in proper scale and proportion regardless of the user's screen resolution. Shareware.
  • Explore Delphi Programming
    About.com Special Features

    Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

    Easy ways to connect two computers for networking purposes. More >

    1. Home
    2. Computing & Technology
    3. Delphi Programming
    4. Coding Delphi Applications
    5. Coding standards
    6. Multi-Resolution Delphi Applications

    ©2009 About.com, a part of The New York Times Company.

    All rights reserved.