I\'m wondering if there are any simple ways to get a list of all fixed-width (monospaced) fonts installed on a user\'s system in C#?
I\'m using .net 3.5 so have acce
Unfortunately ToLogFont function does not fill lfPitchAndFamily field to correct values. In my case it's always 0.
One approximation to detect which fonts might be fixed is the following
foreach ( FontFamily ff in FontFamily.Families ) {
if ( ff.IsStyleAvailable( FontStyle.Regular ) ) {
float diff;
using ( Font font = new Font( ff, 16 ) ) {
diff = TextRenderer.MeasureText( "WWW", font ).Width - TextRenderer.MeasureText( "...", font ).Width;
}
if ( Math.Abs( diff ) < float.Epsilon * 2 ) {
Debug.WriteLine( ff.ToString() );
}
}
}
Keep in mind that they are several false positives, for example Wingdings