Which multi-screen display when the screen delphi

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    edt1: TEdit;
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure SetFormMonitor(Form:TCustomForm;MonitorIndex:integer);
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.btn1Click(Sender: TObject);
begin
  SetFormMonitor(self,StrToInt(edt1.Text));
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  edt1.Text:= IntToStr(Screen.MonitorCount);
end;

procedure TForm2.SetFormMonitor(Form:TCustomForm;MonitorIndex:integer);
begin
  if (MonitorIndex>-1) and (MonitorIndex<Screen.MonitorCount) then//保证屏幕索引在范围内
  begin
      Form.SetBounds(Screen.Monitors[MonitorIndex].Left + ((Screen.Monitors[MonitorIndex].Width - Form.Width) div 2),
        Screen.Monitors[MonitorIndex].Top + ((Screen.Monitors[MonitorIndex].Height - Form.Height) div 2),
         Form.Width, Form.Height);
  end;
end;

end.

Guess you like

Origin www.cnblogs.com/tobetterlife/p/12173044.html