Home | 10% - Off! | New | VCL | DB-Aware | Tools | DB Tools | Apps | Samples | .NET | .NET DB-Aware | .NET Tools | .NET Samples | Kylix | Docs | Bold | Discussion | Sites | Tips | DPFL | Authors | Uploads | RSS | Store | Advertisement | About
DPFL

Information
Introduction
Rules
Advertisement
Categories
Graphics
System
Forms
Windows
Databases
Math routines
Internet
Units/Libraries
RGB2HLS
DzURL
Delphi Procedures and Function Library > Categories > Forms

Click and process to the routine implementation...
SetStaticWindow() SetDynamicWindow() SetWindowCenterOnWindow()

Author Target Keywords Description
Bernt Levinsson (its yours now) D2/D3/(D4?) Forms, Screen Set form inside Screen/Center Form on other Form.
// Non sizible Form
procedure SetStaticWindow(aForm: TForm);
var
  r: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);

  if aForm.Height > r.Bottom then aForm.Height := r.Bottom;

  if aForm.Top < 0 then aForm.Top := 0;

  if aForm.Top+aForm.Height > r.Bottom then
    aForm.Top := r.Bottom-aForm.Height;

  if aForm.Left+aForm.Width >  r.Right then
    aForm.Left := r.Right-aForm.Width;

  if aForm.Left < 0 then aForm.Left := 0;
end;

// Sizible Form
procedure SetDynamicWindow(aForm: TForm);
var
  r: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);

  if aForm.Height > r.Bottom then aForm.Height := r.Bottom;

  if aForm.Top < 0 then aForm.Top := 0;

  if aForm.Top+aForm.Height > r.Bottom then
    aForm.Top := r.Bottom-aForm.Height;

  if aForm.Left+aForm.Width >  r.Right then
    aForm.Left := r.Right-aForm.Width;

  if aForm.Left < 0 then aForm.Left := 0;

  if aForm.Width > r.Right then aForm.Width := r.Right;
end;

// Set Form pos on ref Form
procedure SetWindowCenterOnWindow(FormCenter, FormReference: TForm);
var
  r: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);

  if (FormReference = nil) then begin
    FormCenter.Left := (r.Right div 2) - (FormCenter.Width div 2);
    FormCenter.Top  := (r.Bottom div 2) - (FormCenter.Height div 2);
    Exit;
  end;

  if (not FormReference.Visible) then begin
    FormCenter.Left := (r.Right div 2) - (FormCenter.Width div 2);
    FormCenter.Top  := (r.Bottom div 2) - (FormCenter.Height div 2);
    Exit;
  end;

  FormCenter.Left := ((FormReference.Width div 2) + 
               FormReference.Left)  -  (FormCenter.Width div 2);
  FormCenter.Top := ((FormReference.Height div 2) +
               FormReference.Top)  -   (FormCenter.Height div 2);

  SetStaticWindow(FormCenter);
end;


Advertising on Torry's Delphi Pages

Quick Search
Exact phrase
Title
Description

Useful Books

Advertising on Torry's Delphi Pages

Visit Our Delphi Site.

Up | Home | 10% - Off! | New | VCL | DB-Aware | Tools | DB Tools | Apps | Samples | .NET | .NET DB-Aware | .NET Tools | .NET Samples | Kylix | Docs | Bold | Discussion | Sites | Tips | DPFL | Authors | Uploads | RSS | Store | Advertisement | About
Copyright © Torry's Delphi Pages Torry's Delphi Pages Maintained by A. Berman. Notes? Comments? Feel free to send... Copyright © 1996-2002
All trademarks are the sole property of their respective owners
Do not click! Special anti-spammer page!