Link to home
Start Free TrialLog in
Avatar of akede2001
akede2001

asked on

Delphi screen enumeration

In Delphi, how do you get the left most screen?

For example, using a form that you want to remain hidden, you can set the Left to a negative width:

Self.Left := -Width;

The page this is for contains a TWebBrowser control, and therefore cannot have its visibility set to false, otherwise the pages do not fully load. Per Microsoft, the Left should be assigned -Width.

This is simple on a single screen. However, and for example, I have two screens. My left screen starts at -1440.. so if I set the form left position to -Width, it just appears on my left screen.

How do you enumerate all screens, and get the left most position?
Avatar of dinilud
dinilud
Flag of India image

you mean using multiple desktop?
Avatar of akede2001
akede2001

ASKER

Perhaps, if that's the correct terminology for it.

I'm running Windows. I have two monitors hooked up; same system, same OS. Each monitor shows a desktop, and windows can be drug around the two screens.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland 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
Awesome. That's what I needed. And with that, we have:

function GetMostLeft(): Integer;
var
  x: Integer;
begin
  Result := 0;

  for x := 0 to Screen.MonitorCount - 1 do
    if (Screen.Monitors[x].Left < Result) then
      Result := Screen.Monitors[x].Left;
end;


Works like a charm.
glad i could help:)

ziolko.
Can you tell output this program in each screen(screen1 and screen2).



//////////////.////

Unit1.dfm
=======

object Form1: TForm1
  Left = 195
  Top = 228
  Width = 338
  Height = 190
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 40
    Top = 48
    Width = 177
    Height = 41
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
end

Unit1.pas
========

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   ShowMessage('Left : '+IntToStr(Left)+'      Top : '+IntToStr(Top));
   ShowMessage('Screen Width : '+IntToStr(Screen.Width)+'      Screen Height : '+IntToStr(Screen.Height));
end;

end.