Einzelnen Beitrag anzeigen

dGeek
(Gast)

n/a Beiträge
 
#22

AW: Monitore und dessen Positionen anzeigen (Bildschirmanordnung)

  Alt 18. Feb 2015, 22:47
Ok also ich habe wirklich Eigeninitiative gezeigt und lasse mir nicht alles vorkauen.

Aber nun bin ich am Ende und besser bekomme ich es nicht hin.
(Einfach in eine Form packen die etwa 500px hoch und 400p breit ist).

Wenn mir nun noch jemand helfen könnte die Skalierung richtig hinzubekommen sodass alle Monitore (Shapes) richtig auf der Form angezeigt werden können, wäre ich sehr dankbar.

Delphi-Quellcode:
procedure TForm2.FormShow(Sender: TObject);
const
  aScale = 7;
var
  p: TPoint;
  iMostTop, iPrimaryX, iPrimaryY, iPrimary, i: Integer;
  aShape: TShape;
  aLabel: TLabel;
  procedure drawScreen(iMonCnt: Integer; bPrimary: Boolean = False);
  begin
    p := Point(Screen.Monitors[iMonCnt].Left, Screen.Monitors[iMonCnt].Top);

    if Assigned((FindComponent('aScreen' + IntToStr(iMonCnt + 1)) as TShape)) then
      (FindComponent('aScreen' + IntToStr(iMonCnt + 1)) as TShape).Free;

    aShape := TShape.Create(Self);
    aShape.Parent := Self;
    aShape.Name := 'aScreen' + IntToStr(iMonCnt + 1);
    aShape.Anchors := [];

    aShape.Width := prozentwert(Screen.Monitors[iMonCnt].Width, aScale);
    aShape.Height := prozentwert(Screen.Monitors[iMonCnt].Height, aScale);

    if bPrimary then
    begin
      aShape.Left := (Self.Width div 2) - (aShape.Width div 2);
      aShape.Top := iMostTop; // (Self.Height div 2) - (aShape.Height div 2);
      iPrimaryX := aShape.Left;
      iPrimaryY := aShape.Top;
    end
    else
    begin
      aShape.Left := prozentwert(p.X, aScale) + iPrimaryX;
      aShape.Top := prozentwert(p.Y, aScale) + iPrimaryY;
    end;

    if Assigned((FindComponent('aLabel' + IntToStr(iMonCnt + 1)) as TLabel)) then
      (FindComponent('aLabel' + IntToStr(iMonCnt + 1)) as TLabel).Free;

    aLabel := TLabel.Create(Self);
    aLabel.Parent := Self;
    aLabel.Name := 'aLabel' + IntToStr(iMonCnt + 1);
    aLabel.Anchors := aShape.Anchors;
    aLabel.Font.Size := -13;
    aLabel.Font.Style := [fsBold];
    aLabel.AutoSize := False;
    aLabel.Left := aShape.Left + 1;
    aLabel.Top := aShape.Top + (aShape.Height div 2) - (aLabel.Height div 2);
    aLabel.Width := aShape.Width - 2;
    aLabel.Alignment := taCenter;
    aLabel.Caption := IntToStr(iMonCnt + 1);
    aLabel.Visible := True;
    aLabel.BringToFront;

    Repaint;
  end;

begin
  iMostTop := 0;
  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if Screen.Monitors[i].Top < iMostTop then
      iMostTop := Screen.Monitors[i].Top;
  end;
  iMostTop := iMostTop + 20;

  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if Screen.Monitors[i].Primary then
    begin
      iPrimary := i;
      drawScreen(i, True);
      break;
    end;
  end;

  for i := 0 to Screen.MonitorCount - 1 do
  begin
    if i = iPrimary then
      Continue;

    drawScreen(i);
  end;
end;
  Mit Zitat antworten Zitat