Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2024-05-12 06:50:12 +00:00
17 Font
Fellippe Heitor edited this page 2021-12-22 12:12:15 -03:00

The Font property holds the handle of the loaded font associated with a control. It must be set using the SetFont method and must not be directly manipulated with QB64's builtin font commands.

SetFont method

Control(ControlID).Font = SetFont(FontName$, FontSize%)
  • FontName$ must reference a font file. Both TTF and OTF fonts are accepted.
  • Multiple fonts can be specified as alternatives in case one fails to load. Indicate the desired fonts separated by a question mark.
    • If you don't specify a path, the current path is used.
    • In Windows, if a path isn't specified the default font location C:\Windows\Font is searched.
  • FontSize% is in pixels, not points.

You can also use QB64's builtin fonts (_FONT 16 or _FONT 8). To do so, specify only the FontSize% parameter:


Control(Label1).Font = SetFont("", 8)
Control(Label2).Font = SetFont("", 16)

To specify a font at design time, select it from the list or specify the font file and separate the desired size with a comma. To type a font file name that's not on the list, right click the "Font" label and untick "Show system fonts list":

Use a question mark (?) to specify multiple fonts. This is useful when you wish to specify replacement fonts in case the desired font isn't found or can't be loaded.

 Control(ControlID).Font = SetFont("font1.ttf?relative/path/font2.ttf?c:\absolutpath\font3.ttf", FontSize%)

The default font for new controls is segoeui.ttf in Windows, which then falls back to arial.ttf if the former can't be loaded. The next font attempted is also Arial, but InForm attempts to load it from the default fonts folder on macOS. If all fails that probably means we're in Linux and then either Arial or Liberation fonts are loaded. If all fails, the font that's shipped with InForm is then loaded from InForm/resources/NotoMono-Regular.ttf. All of them are attempted at size 12.

If you don't set a control's font property, it will inherit its container's font (either the main form or a frame, if any).

Controls that can use the Font property: