-
Notifications
You must be signed in to change notification settings - Fork 16
Font
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.
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:
Examples:
Control(Label1).Font = SetFont("", 8)
Control(Label2).Font = SetFont("", 16)
To specify a font at design time, specify the font file and separate the desired size with a comma:
fontfile,size
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 setup for new forms/controls is:
segoeui.ttf?arial.ttf?/Library/Fonts/Arial.ttf?InForm/resources/NotoMono-Regular.ttf?cour.ttf, 12
The default setup above will try to load segoeui.ttf in Windows, then fallback to arial.ttf if the former can't be loaded. The next font specified 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 the font that's shipped with InForm is then loaded from InForm/resources/NotoMono-Regular.ttf. The final attempt it to load Courier New from cour.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).