You are using WinForms, but looking at the WPF documentation. The WinForms FontFamily
class constructor doesn't support explicit fallback fonts. Only one font's face name can be specified for the FontFamily
constructor. If it can't find that specified font, the operating system automatically selects a fallback, based on various heuristics (this article is very old, so some of these details have changed, but many of them are the same).
In general, WinForms applications should not hardcode a particular font. What you want to use in your UI is the standard, system dialog font, which you can obtain using SystemFonts.MessageBoxFont
. Set it in the constructor for each of your forms, so that all child controls automatically pick it up, as advised here. This not only ensures that the font will be available, but it allows your UI to adapt to the user's preferences.
If you absolutely must hard-code a font, then you will need to enumerate the installed fonts and use a manual fallback algorithm—see if the font face you want exists in the enumerated list, and if not, fall back to an alternative. Note that "Comic Sans MS" and "Verdana" are both "safe" fonts; they'll be there on any Windows system that the .NET Framework can run on, unless the user has explicitly removed them. (And they might have. Comic Sans is an abomination.)
Perhaps an even better alternative (again, if you absolutely must have custom, non-standard fonts) would be to bundle the font(s) you need with your application. You can do this by creating a private font collection, which maintains fonts specifically for your application. A private font collection can include font files provided by the application vendor that are not installed on the system.