24 Votes

Lazarus: Determine Default-Font or System-Font of Form, Label, Edit and Button

Question by Guest | Last update on 2024-01-23 | Created on 2013-12-12

When creating a new Form in Lazarus and when putting some Buttons, Edit-Fields, Memos or Labels onto it, all of these elements and controls have the value "default" for their font name property set. This makes the elements and controls appear native on the corresponding operating system because the default font of the respective system is used. Of course, this is a good idea for platform independent programming.

However, I would like to know the exact font name of the font that is used (the default font of the operating system). I want to know the font that is hidden by the "default" property, because this can be totally different from system to system and even from version to version of the same system.

Is there any possibility of how to retrieve the font name of my Form or my Memo if it is set to "default"?

ReplyPositiveNegativeDateVotes
3Best Answer5 Votes

Using the function GetFontData, you can determine the font of an arbitrary control.

For example, you can use it like this:

Form1.Caption := GetFontData(Form1.Font.Handle).Name;   

This sets the Caption of Form1 to the Name of the Font that is used for Form1.

If "FontName" is set to "Default" for Form1, you will receive the name of the default system font with this.
Last update on 2024-01-23 | Created on 2013-12-12

ReplyPositive Negative
-11 Vote

This works in Windows, I don't know about Linux or other platforms...

Uses Windows;

Function LoadFont(Filename : String) : Integer;
Begin
  LoadFont := AddFontResource(PChar(Filename));
  SendMessage(HWND_BroadCast, WM_Fontchange, 0, 0);
End;

Procedure UnloadFont(Filename : String);
Begin
  RemoveFontResource(PChar(Filename));
  SendMessage(HWND_BroadCast, WM_Fontchange, 0, 0);
End;

2014-04-11 at 21:15

ReplyPositive Negative
00 Votes

The question was about how to determine the default font of the system that is used when the font is set to "default" in Lazarus.

With your function, you can load a font from a file name instead of determining the name.
2014-04-14 at 00:27

Positive Negative
Reply
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.