Mega Code Archive

 
Categories / Delphi / Examples
 

How to get a strings width in pixels, not in characters

Sometimes you may need to know how wide a string is in pixels, e.g. for dynamically generated forms. This depends of course on the selected font characteristics. Windows and the VLC provide a function TextWidth which is a method of TCanvas: TCanvas.TextWidth(sString);