this slowpoke moves

Get Screen Diagonal

function GetScreenDiagonal(AMonitor: Integer; AInch: Boolean = True): Integer;
const
    Factor: array[Boolean] of Single = (2.54, 1);
var
    Width, Height: Single;
begin
  Width := Screen.Monitors[AMonitor].Width / Screen.PixelsPerInch * Factor[AInch];
  Height := Screen.Monitors[AMonitor].Height / Screen.PixelsPerInch * Factor[AInch];
	  Result := Round(Sqrt(Sqr(Width) + Sqr(Height)));
	end;

	function GetScreenDiagonalExact(AMonitor: Integer; AWidthInCm: Single;
	  AInch: Boolean = True): Integer;
	const
	  Factor: array[Boolean] of Single = (1, 2.54);
	var
	  Height, PixelsPerInch: Single;
	begin
	  PixelsPerInch := Screen.Monitors[AMonitor].Width / AWidthInCm * 2.54;
	  Height := Screen.Monitors[AMonitor].Height / PixelsPerInch * 2.54;
	  Result := Round(Sqrt(Sqr(AWidthInCm / Factor[AInch]) + Sqr(Height / Factor[AInch])));
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(GetScreenDiagonal(0, True)) + ' Zoll');
	  ShowMessage(IntToStr(GetScreenDiagonalExact(0, 47.4, True)) + ' Zoll');
	  ShowMessage(IntToStr(GetScreenDiagonal(0, False)) + ' Zentimeter');
	  ShowMessage(IntToStr(GetScreenDiagonalExact(0, 47.4, False)) + ' Zentimeter');
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate