When you instantiate a font class, the Windows system replaces the font with a Microsoft Sans serif font when the passed-in parameter is a nonexistent or not installed typeface.
Msdn:
" How to: construct Font families and fonts. ">for more information on how to construct fonts, see how to:construct Font families and Fonts. windows Forms applications support TrueType fonts and has limited support for OpenType Fonts. if you attempt to use a font which is not supported, or the" the "and" the font is not installed on the machine that's running the APPL Ication, the Microsoft Sans Serif font would be substituted.
Scenario :
Using the New font ("Font",.....), when the font doesn't exist, I thought I'd replace it with the system's default input method, and then I looked at MSDN and found that it didn't seem to be the case. Decide to look up the source code.
Source :
System.Drawing.Font class
1 Private voidInitialize (stringFamilyname,floatEmSize, FontStyle style, GraphicsUnit unit,bytegdiCharSet,BOOLGdiverticalfont)2 {3 This. Originalfontname =familyname;4 This. Setfontfamily (New FontFamily(Font.stripverticalname (Familyname),true));5 This. Initialize ( This. fontFamily, emSize, style, unit, gdiCharSet, Gdiverticalfont);6}
System.Drawing.FontFamily class
1 Internal FontFamily (stringbool createdefaultonfail)2{3 this. Createdefaultonfail = createdefaultonfail; 4 this. createfontfamily NULL ); 5 }
1 Private voidCreatefontfamily (stringname, fontcollection fontcollection)2 {3IntPtr IntPtr =IntPtr.Zero;4INTPTR handle = (Fontcollection = =NULL) ?IntPtr.Zero:fontCollection.nativeFontCollection;5 intnum = SafeNativeMethods.Gdip.GdipCreateFontFamilyFromName (name,NewHandleRef (fontcollection, handle), outintPtr);6 if(num! =0)7 {8 if( This. Createdefaultonfail)9 {TenINTPTR =FontFamily. Getgdipgenericsansserif (); One } A Else - { - if(num = = -) the { - Throw NewArgumentException (SR. GetString ("Gdiplusfontfamilynotfound",New Object[] - { - name + })); - } + if(num = = -) A { at Throw NewArgumentException (SR. GetString ("Gdiplusnottruetypefont",New Object[] - { - name - })); - } - ThrowSafeNativeMethods.Gdip.StatusException (num); in } - } to This. Setnativefamily (INTPTR); +}
1 Private StaticIntPtr Getgdipgenericsansserif ()2 {3IntPtr zero =IntPtr.Zero;4 intnum = Safenativemethods.gdip.Gdipgetgenericfontfamilysansserif( outzero);5 if(num! =0)6 {7 ThrowSafeNativeMethods.Gdip.StatusException (num);8 }9 returnZero;Ten}
Conclusion:
"SafeNativeMethods.Gdip.GdipGetGenericFontFamilySansSerif" method, the Microsoft Sans Serif font is returned under Windows system.
This shows that when the instantiated font does not exist, Windows pinned back to the Microsoft Sans Serif font, regardless of the system default font.