Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.687 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Textgröße (Windows 11, Barrierefreiheit)

  Alt 22. Aug 2023, 08:45
Falls Du Interesse hast von einem graphischen Objekt die gebrauchten Dimensionen auf dem Bildschirm zu erfahren, so mache ich das:
Delphi-Quellcode:
function GetFontSize(const AText: String; const AFont: TFont; out AWidth, AHeight: Integer): Boolean;
var
  LBMP: TBitmap;
begin
  Result := False;
  AWidth := 0;
  AHeight := 0;
  LBMP := TBitmap.Create;
  try
    LBMP.Canvas.Font.Assign(AFont);
    AWidth := LBMP.Canvas.TextWidth(AText);
    AHeight := LBMP.Canvas.TextHeight(AText);
    Result := ((AWidth <> 0) or (AHeight <> 0));
  finally
    LBMP.Free;
  end;
end;
Die Argumente kurz erklärt:
- AText = dein string von dem Du die Dimensionen benötigst
- AFont = deine verwendete Font
- AWidth = Rückgabe der Breite
- AHeight = Rückgabe der Höhe

LG, KodeZwerg.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat