Method to set the default font for controls depending on the platform?

Hi All,

Does anyone have a recommendation for setting the default font for all controls depending on the platform? I am running into serious appearance issues on some Windows system and most Linux systems if I just use “System” and change the font size - especially with ListBoxes and Combo Boxes.

Or, is there a way for us to define what the app uses for the “System” font so that “System” is the font that we want used?

That defeats the purpose of System. Assign a dynamic constant for the font, and define your font by platform with the constant. I have tested and this works as expected on Mac and Windows. This works just like the Menu Shortcuts by platform.


I’ve added some info to that case. It turns out that’s only an IDE usability issue, the controls do in fact accept the Constant for Font.

I was also seeing what Norman stated, so assumed it wasn’t an option. I’ll try hitting [ENTER] after setting the constant.

While Tim Parnell’s method works for defining the font as the constant, it appears that the value for the constant is ignored. I set the constant to point to “Courier” (which is verified and on the test system and shows up in Xojo’s font pick lists). but the font in the app is still some form of Sans Serif font (I’m assuming the normal font for System) instead of the expected monospaced mess.

I’m working up an example for a report.

This could be because of the issues identified in several other cases like
where the setting in the IDE of the new property has no effect at runtime

Every property that was renamed in this way is suspect

This is on 19r1.1 as well.

The constant setting is saved and shows in both the IDE property and the text source. and using the same font (Courier 10 Pitch) from the font picker sets the controls’ font properly.

If you’re on Windows it must be “Courier New” and if the font you set is not available on the system it will revert to System.

This is my “base installation safe” monospaced constant:

	#tag Constant, Name = kMonospacedFont, Type = String, Dynamic = False, Default = \"", Scope = Public
		#Tag Instance, Platform = Mac OS, Language = Default, Definition  = \"Menlo"
		#Tag Instance, Platform = Windows, Language = Default, Definition  = \"Courier New"
	#tag EndConstant

If you have recommendations for Linux, I’m all ears!

I was on Linux and - like I mentioned - that’s same name that shows in Xojo’s Font Picker. I’m not trying to use Courier, I was trying to verify that the constant was not being set since “FreeSans” *what I do want to use) and the System font are very close in appearance.

As to a recommendation for Linux, I use DejaVu Sans Mono since it’s installed on all full desktop Linux distros.

As an alternative, subclass your controls and have them set the font you want from a constant in the Open event. Use the subclasses in your windows. The additional advantage is that you can later define all sorts of behavior across the app easily. For example, my pushbuttons will grow by about 5 pixels or so on platforms that are not the Mac and my Listboxes will all use the same row highlighting technique, easily changed later if I decide on something better or just different.

I started there, but I was trying to not have to edit over 1,300 controls :). And, we all know how fidgety the IDE becomes when you’re working with that large of a collection of items.

BBEdit search & replace on a text project works pretty well :stuck_out_tongue:

Just to provide a bit of info for the record, here’s my constant definition:

#tag Constant, Name = kSystemFont, Type = String, Dynamic = False, Default = \"", Scope = Public #Tag Instance, Platform = Mac OS, Language = Default, Definition = \"Arial" #Tag Instance, Platform = Linux, Language = Default, Definition = \"FreeSans" #Tag Instance, Platform = Windows, Language = Default, Definition = \"Helvetica" #tag EndConstant
The interesting thing is that this doesn’t work on any of the platforms, so since Tim P is using such a mechanism, it must have worked properly in previous Xojo versions. Tim, could you verify that your constant mechanism actually works under 19r1.1?

So does VS Code - which I prefer to BBEdit since it’s on all of my platforms :smiley:

I had prior to posting:

Running attached to the debugger
macOS 10.14.6
Windows 10


Arial Mac

Helvetica Windows

Menlo Mac

Courier New Windows

Here’s my report. An example is attached that doesn’t work on any platform using 19r1.1 here.


You should be able to use the IDE’s search and replace tools if you go three subclass route.

None of your constants are prefixed with # the way they’re supposed to be for this to work.