02 Votes

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

Question by Guest | 2013-12-12 at 10:39

When creating a new Form in Lazarus and when putting some Buttons, Edit-Fields, Memos or Labels onto it, all elements and controls have the value "default" for their font name property. This makes the elements and controls appear native on the corresponding operating system because the default font of this 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 determine the font name of my Form or my Memo if it is set to "default"?

ReplyPositiveNegativeDateVotes
2Best Answer4 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 you have set the Font Name of Form1 to "default", you can get the name of the default system font with this.
2013-12-12 at 14:50

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

Determine Font from Image

Open Question | 1 Answer

Print Word in all System Fonts

Tutorial | 0 Comments

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.