unit CropForms;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: CropForms
// Property: Forms.TScreen.Height
// Property: Forms.TScreen.Width
// Variable: Forms.Screen

// BeginCode
{
The following code determines the height of all forms on the
screen and resizes any that are taller than the screen height.
}
procedure TForm1.Button1Click(Sender: TObject);
var I: Integer;
begin
with Screen do
  for I := 0 to FormCount-1 do
    begin
    if Forms[I].Top < 0 then
    begin
      Forms[I].Height := Forms[I].Height + Forms[I].Top;
      Forms[I].Top := 0;
    end;
    if Forms[I].Left < 0 then
    begin
      Forms[I].Width := Forms[I].Width + Forms[I].Left;
      Forms[I].Left := 0;
    end;
    if Forms[I].Left + Forms[I].Width > Width then
      Forms[I].Width := Width - Forms[I].Left;
    if Forms[I].Top + Forms[I].Height > Height then
      Forms[I].Height := Height - Forms[I].Top;
    end;
end;
// EndCode
// EndExample: CropForms
end.
