Solved

Little form in the lower right corner

Posted on 2004-08-14
10
330 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:wildzero
  • 8
  • 2
10 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11803321
//........ 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
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11803322
//........ 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.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11803359
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
0
 
LVL 10

Author Comment

by:wildzero
ID: 11803387
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'?
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 250 total points
ID: 11803412
What about the next code ?

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;

procedure TForm2.TimerTimer(Sender: TObject);
begin
  FormShow(Self);
end;
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:esoftbg
ID: 11803444
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;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11803460
If the Timer.Interval is 2000, then every 2 seconds Form2 corrects itself position if needed !!!!
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11803480
download the example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21094171.zip
0
 
LVL 10

Author Comment

by:wildzero
ID: 11804949
Thats great :)
many thanks
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11805064
Hi wildzero, you are welcome !
Glad to be in help !
Best regards,
emil      :~))
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now