C # Get All Available FontFamily

I have an input box and people type in the font and it saves what they type like a jpeg. Everything is working fine. But when they type the name of the font, for example, " times new roman ", it must be correctly capitalized to " times new roman " or it does not work!

Is it possible to somehow sort through all available fonts and present them to them as a drop-down list so that there are no problems with spelling, and they will definitely use only fonts in the system?

+4
source share
4 answers

Just use the following code:

 FontFamily[] ffArray = FontFamily.Families; foreach (FontFamily ff in ffArray) { //Add ff.Name to your drop-down list } 
+9
source

Or you can just bind it directly:

<ComboBox ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />

+7
source

I have font lists in several places in my application, so I like to download the list once and reuse the list to bind to the controls.

 public List<string> GetFontFamilies() { List<string> fontfamilies = new List<string>(); foreach (FontFamily family in FontFamily.Families) { fontfamilies.Add(family.Name); } return fontfamilies; } 
+2
source

This is almost the same as Gary's answer, but a little more compact:

 public static readonly List<string> FontNames = FontFamily.Families.Select(f => f.Name).ToList(); 
0
source

Source: https://habr.com/ru/post/1344150/


All Articles