Recent

Author Topic: Accurate Positioning of Multiple Forms  (Read 1868 times)

simsee

  • Full Member
  • ***
  • Posts: 184
Accurate Positioning of Multiple Forms
« on: April 11, 2017, 06:37:14 pm »
I need to place four forms (TForm) in the screen, in a way that they occupy the entire screen, but without overlapping between them. I tried to achieve this using various properties (i.e. Form.Left/Right/...Height/Width, Screen.Left/Right... etc, Form.ClientXXX), but I have always get imprecisions when I change the physical screen of computer, or the OS platform. Is there a possible solution? Thanks for the help

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Accurate Positioning of Multiple Forms
« Reply #1 on: November 07, 2017, 04:47:33 am »
This would be my solution...  :)
Code: Pascal  [Select][+][-]
  1. UNIT uWorkArea;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Graphics, Controls, ExtCtrls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Panel1: TPanel;
  12.    Panel2: TPanel;
  13.    Panel3: TPanel;
  14.    Panel4: TPanel;
  15.  
  16.    Procedure FormCreate     (Sender: TObject);
  17.    Procedure FormResize     (Sender: TObject);
  18.    Procedure Arrange4Panels (pnl1, pnl2, pnl3, pnl4: TPanel; iBorder: Integer);
  19.   End;
  20.  
  21.  VAR
  22.   Form1: TForm1;
  23.  
  24. Implementation
  25.  {$R *.LFM}
  26.  
  27. Procedure TForm1.Arrange4Panels(pnl1, pnl2, pnl3, pnl4: TPanel; iBorder: Integer);
  28.   Var
  29.    iX, iY: Integer;
  30.  Begin
  31.   iX:= (ClientWidth  - 3*iBorder) Div 2;
  32.   iY:= (ClientHeight - 3*iBorder) Div 2;
  33.  
  34.   pnl1.SetBounds(iBorder, iBorder, iX, iY);
  35.   pnl2.SetBounds(iBorder*2 +iX, iBorder, iX, iY);
  36.   pnl3.SetBounds(iBorder, iBorder*2 +iY, iX, iY);
  37.   pnl4.SetBounds(pnl2.Left, pnl3.Top, iX, iY);
  38.  End;
  39.  
  40. Procedure TForm1.FormResize(Sender: TObject);
  41.  Begin
  42.   Arrange4Panels(Panel1, Panel2, Panel3, Panel4, 0);
  43.  End;
  44.  
  45. Procedure TForm1.FormCreate(Sender: TObject);
  46.  Begin
  47.   DoubleBuffered:= True;
  48.  
  49.   Panel1.Color:= clBlue;
  50.   Panel2.Color:= clYellow;
  51.   Panel3.Color:= clWhite;
  52.   Panel4.Color:= clGreen;
  53.  
  54.   Panel1.BevelOuter:= bvNone;
  55.   Panel2.BevelOuter:= bvNone;
  56.   Panel3.BevelOuter:= bvNone;
  57.   Panel4.BevelOuter:= bvNone;
  58.  End;
  59.  
  60. END.

Maybe it has something to do with Screen.WorkAreaWidth or Screen.WorkAreaLeft and so on...
So I would check LAZARUS 1.8 RC5 or the Trunk-Version... maybe it's fixed there...

On WINDOWS the user can set a custom window border, so every window has got a bigger border for example... maybe it has something to do with it...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018