00 Votes

Lazarus: Get Default Font Size of Application and Controls

Question by Guest | 2015-10-30 at 22:41

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, Edit fields, or listboxes.

I have tried to read out the font size with storing 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
1Best Answer1 Vote

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 and after that, we have to convert the value provided from this into the font size we can work with.
2015-11-01 at 17:04

ReplyPositive Negative
Reply

Related Topics

PHPExcel: Change Font Size

Question | 1 Answer

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.