»  The Delphi Column 

  Property ALIGN of a component

In this column, we have a detailed look at the property Align of visual components such as panels, memo's, grids and so on.

Align determines how a component aligns within its container (its parent, for example a form or another panel). You use it to align the component to the top, bottom, left, or right of its parent; it remains there even when the size of its parent changes.

A panel aligned to the top of a form is often used as a "toolbar" with various components on it, such as speedbuttons. A panel aligned to the bottom is often used to contain a "status bar".

Note: don't confuse Align with "Alignment", that determines how text is aligned (left, center, right).

Property Align
The form was resized.
Property Align
Original dimensions of the form.

Possible values for Align

  • alNone: the default value. The component remains where it is positioned on a form or panel.
  • alTop: position at the top of its parent. Its height remains unchanged, but its width changes when the parent is resized.
  • alBottom: position at the bottom of its parent. Height remains unchanged, but width changes when the parent is resized.
  • alLeft: position at the left of its parent. Height changes when the parent is resized, but width remains unchanged.
  • alRight: position at the right of its parent. Height changes when the parent is resized, but width remains unchanged.
  • alClient: the component fills the entire client area in its parent. Both height and width change when the parent is resized.

Code example: create aligned panels at runtime

var
  Panel1, Panel2: TPanel;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Create a new panel and align it to the top of Form1 
  Panel1 := TPanel.Create(Self);
  Panel1.Parent := Self;
  Panel1.Align := alTop;
  Panel1.Height := (ClientHeight div 4);
  Panel1.Caption:= 'Panel1';

  // Create a new panel and align it to the remaining client size
  Panel2 := TPanel.Create(Self);
  Panel2.Parent := Self;
  Panel2.Align := alClient;
  Panel2.Caption:= 'Panel2';
end;

In the example above, Self stands for Form1. Thus, Form1 becomes the parent of the two panels.


Database Tutorials  FAQ  Crash Course Delphi  Tips  Source Code  Downloads  Links

© Copyright 1999-2019 
DelphiLand