22 Votes

Lazarus: Get Default Font Size of Application and Controls

Question by Guest | Last update on 2026-10-10 | Created on 2015-10-30

I would like to somehow determine the default font size of my application. I mean the font size, that is used for all of the controls such as Panel, Button, Memo or Edit fields, or listboxes.

I have tried to read out the font size with catching the value from Form1.Font.Size or Label1.Font.Size into a variable, but unfortunately, the result is always 0. Even during program execution, I get this 0 value, although the controls are having a font size that is visible.

What am I doing wrong here? And how to retrieve the correct value?

ReplyPositiveNegative
2Best Answer2 Votes

If Font.Size is 0, that means, that the default font size should be used.

You can get the real size in the following way:

function GetDefaultFontSize: integer;
var
  fd: TFontData;
begin
  fd := GetFontData(prog.Font.Handle); 
  result := round((fd.Height * 72 / Font.PixelsPerInch) * (-1));  
end;

As you can see, I have written a small function for this, that should demonstrate how to proceed.

First of all, we are catching the FontData of the program ("prog" is our main form) and after that, we have to convert the value provided from this into the font size we can work with.
Last update on 2026-10-10 | Created on 2015-11-01

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.