unit Unit1;
interface
uses
Windows, Messages, Forms, Classes, Controls, ComCtrls, ExtCtrls, StdCtrls, Dialogs;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure MonitorPanelResize(Sender: TObject);
private
procedure ShowMonitors();
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses
SysUtils, Math;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
liZ1: Integer;
lPanel: TPanel;
begin
Position := poScreenCenter;
Color := $444444;
lPanel := TPanel.Create(Self);
lPanel.Parent := Self;
lPanel.
Name := '
MonitorPanel';
lPanel.Caption := '
';
lPanel.ParentBackground := true;
lPanel.BevelOuter := bvNone;
lPanel.AlignWithMargins := true;
lPanel.Margins.SetBounds(10,10,10,10);
lPanel.Align := alClient;
lPanel.OnResize := MonitorPanelResize;
ShowMonitors();
end;
procedure TForm1.MonitorPanelResize(Sender: TObject);
begin
ShowMonitors();
end;
procedure TForm1.ShowMonitors();
var
liZ1: Integer;
lScaleFactor: Extended;
lOffsetX: Integer;
lOffsetY: Integer;
lPanel: TPanel;
lParentPanel: TPanel;
begin
lParentPanel := TPanel(Self.FindComponent('
MonitorPanel'));
for liZ1 := lParentPanel.ControlCount - 1
downto 0
do
begin
lParentPanel.Controls[liZ1].Free;
end;
lScaleFactor := Min(lParentPanel.Width / Screen.DesktopWidth,lParentPanel.Height / Screen.DesktopHeight);
lOffsetX := Round(Screen.DesktopLeft * lScaleFactor);
lOffsetY := Round(Screen.DesktopTop * lScaleFactor);
for liZ1 := 0
to Screen.MonitorCount - 1
do
begin
lPanel := TPanel.Create(lParentPanel);
lPanel.Parent := lParentPanel;
lPanel.ParentBackground := false;
lPanel.Color := $888888;
lPanel.BevelInner := bvLowered;
lPanel.BevelWidth := Max(Round(10 * lScaleFactor),1);
lPanel.Caption := IntToStr(Screen.Monitors[liZ1].MonitorNum + 1);
lPanel.Top := Round(Screen.Monitors[liZ1].Top * lScaleFactor) - lOffsetY;
lPanel.Left := Round(Screen.Monitors[liZ1].Left * lScaleFactor) - lOffsetX;
lPanel.Height := Round(Screen.Monitors[liZ1].Height * lScaleFactor);
lPanel.Width := Round(Screen.Monitors[liZ1].Width * lScaleFactor);
lPanel.Font.Size := Max(lPanel.Height
div 2,8);
end;
end;
end.