Link to home
Start Free TrialLog in
Avatar of wildzero
wildzero

asked on

Little form in the lower right corner

Hey there
What I have is two forms
Form1 and Form2
Form1 has a button that opens Form2, now what I need, is Form2 to be positioned in the lower right corder(just above the date and time).
This needs to work on all different screen resoultions as well....


So basically when it comes down to it, position From2 in the lower right corner of the screen - on any resoultion.

Cheers
NIck
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

//........ Project :

program Q_21094171;
uses
  Forms,
  Unit1_Q_21094171 in 'Unit1_Q_21094171.pas' {Form1},
  Unit2_Q_21094171 in 'Unit2_Q_21094171.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

//........ Unit1:

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

uses
  Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Form2.Hide;
end;

end.

//........ Form1:

object Form1: TForm1
  Left = 200
  Top = 112
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Form1'
  ClientHeight = 94
  ClientWidth = 184
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDefaultPosOnly
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 16
    Top = 10
    Width = 96
    Height = 25
    Caption = 'Show Form2'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 16
    Top = 48
    Width = 96
    Height = 25
    Caption = 'Hide Form2'
    TabOrder = 1
    OnClick = Button2Click
  end
end

//........ Unit2:

unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    procedure FormShow(Sender: TObject);
  private  { Private declarations }
  public   { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormShow(Sender: TObject);
begin
  Top := Screen.Height - Height - 32;
  Left := Screen.Width - Width;
end;

end.

//........ Form2:

object Form2: TForm2
  Left = 192
  Top = 128
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsNone
  Caption = 'Form2'
  ClientHeight = 30
  ClientWidth = 120
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 2
    Top = 4
    Width = 112
    Height = 21
    ReadOnly = True
    TabOrder = 0
    Text = 'I am above the clock'
  end
end
//........ Project :

program Q_21094171;
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
procedure TForm2.FormShow(Sender: TObject);
var
  R:      TRect;
begin
  Memo.Clear;
  SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
  Memo.Lines.Add('Work area is the portion of the screen not obscured by the taskbar');
  Memo.Lines.Add('Left=' + IntToStr(R.Left));
  Memo.Lines.Add('Top=' + IntToStr(R.Top));
  Memo.Lines.Add('Right=' + IntToStr(R.Right));
  Memo.Lines.Add('Bottom=' + IntToStr(R.Bottom));
  Top := R.Bottom - Height;
  Left := R.Right - Width;
end;

//........

object Form2: TForm2
  Left = 193
  Top = 107
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsNone
  Caption = 'Form2'
  ClientHeight = 126
  ClientWidth = 120
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Memo: TMemo
    Left = 2
    Top = 2
    Width = 112
    Height = 120
    ReadOnly = True
    TabOrder = 0
  end
end

emil
Avatar of wildzero
wildzero

ASKER

Hey there,

Thanks for the speedy reply.
I see the code Top := Screen.Height - Height - 32;
but - what happens if they have re-sized there task bar 'two lines high'?
ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
procedure TForm2.FormShow(Sender: TObject);
var
  B:      Boolean;
  L:      Integer;
  T:      Integer;
  R:      TRect;
begin
  B := False;
  SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
  T := R.Bottom - Height;
  L := R.Right - Width;
  if (T<>Top) then
  begin
    B := True;
    Top := T;
  end;
  if (L<>Left) then
  begin
    B := True;
    Left := L;
  end;
  if B then
  begin
    Memo.Clear;
    Memo.Lines.Add('Work area is the portion of the screen not obscured by the taskbar');
    Memo.Lines.Add('Left=' + IntToStr(R.Left));
    Memo.Lines.Add('Top=' + IntToStr(R.Top));
    Memo.Lines.Add('Right=' + IntToStr(R.Right));
    Memo.Lines.Add('Bottom=' + IntToStr(R.Bottom));
  end;
end;

procedure TForm2.TimerTimer(Sender: TObject);
begin
  FormShow(Self);
end;
If the Timer.Interval is 2000, then every 2 seconds Form2 corrects itself position if needed !!!!
download the example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21094171.zip
Thats great :)
many thanks
Hi wildzero, you are welcome !
Glad to be in help !
Best regards,
emil      :~))