Recent

Author Topic: TForm.Position for Multi monitor systems...  (Read 14305 times)

corpsman

  • New member
  • *
  • Posts: 9
    • My Delphi / Lazarus Programming site ( www.Corpsman.de )
TForm.Position for Multi monitor systems...
« on: November 16, 2009, 07:46:02 am »
Hello, and good morning,

I have a feature request and my solution for multimonitor users, hope that i selected the right sub forum.

I'm using a multi monitor system under Linux ( Kubuntu Karmic 9.10 ) 32 Bit, and the actual SVN Lazarus version.

If i set the position value of the TForm1 to "poScreenCenter" i unhappily do not get the solution i want to.

poScreenCenter in my oppinion means centered on the monitor in which i am currently working, and this monitor is the one in which my mouse is lokated.

poScreenCenter in the aktual Lazarus version means centered on Monitor 0. So i wrote the following code, witch could make the "poScreenCenter" as i expected it ( Working only when the Position value is set to "poDesigned" )

Code: [Select]
Function PointInRect(P: TPoint; R: TRect): boolean;
Var
  t: Integer;
Begin
  If r.left > r.right Then Begin
    t := r.left;
    r.left := r.right;
    r.right := t;
  End;
  If r.top > r.bottom Then Begin
    t := r.Bottom;
    r.bottom := r.top;
    r.top := t;
  End;
  result := (r.left <= p.x) And (r.right >= p.x) And
    (r.top <= p.y) And (r.bottom >= p.y);
End;

Procedure TForm1.FormCreate(Sender: TObject);
Var
  i: Integer;
  r: Trect;
Begin
  If screen.MonitorCount <> 1 Then Begin
    For i := 0 To screen.MonitorCount - 1 Do Begin
      r := screen.Monitors[i].BoundsRect;
      If PointInRect(Mouse.CursorPos, r) Then Begin
        left := (screen.Monitors[i].width - form1.width) Div 2 + screen.Monitors[i].BoundsRect.left;
        top := (screen.Monitors[i].height - form1.height) Div 2 + screen.Monitors[i].BoundsRect.top;
        break;
      End;
    End;
  End
  Else Begin
    left := (screen.width - form1.width) Div 2;
    top := (screen.height - form1.height) Div 2;
  End;
..

I found out that this solution don't work under Win32, because there is some Problems with the screen.Monitors, so my solution maybe is not the best one.

But i hope that some of you find a way to do the same under Windows, and integrate it in the LCL.

Corpsman
--
Just try it.

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
Re: TForm.Position for Multi monitor systems...
« Reply #1 on: November 19, 2009, 08:20:41 am »
TForm has DefaultMonitor property which defines which of the monitors will be choosen for positioning. So if you have your main/active form on the second monitor then poScreenCenter place your form at the center of the second monitor.

corpsman

  • New member
  • *
  • Posts: 9
    • My Delphi / Lazarus Programming site ( www.Corpsman.de )
Re: TForm.Position for Multi monitor systems...
« Reply #2 on: January 02, 2010, 04:43:24 pm »
no you misunderstood, the second and third forms are not the problem.

I use this code to place the first / main form. Your answer explains why the other forms get the right / same monitor on which the main form is placed.
--
Just try it.

 

TinyPortal © 2005-2018