C# 获取系统所有字体
获取已安装的所有字体列表
System.Drawing.FontFamily
1 StringBuilder str = new StringBuilder(2000); 2 InstalledFontCollection fonts = new InstalledFontCollection(); 3 foreach (FontFamily family in fonts.Families) 4 { 5 str.Append(family.Name); 6 str.AppendLine(); 7 } 8 ContentTextBlock.Text = str.ToString();
获取区域语言字体列表
System.Windows.Media.FontFamily
1 StringBuilder str = new StringBuilder(2000); 2 CultureInfo currentCulture = CultureInfo.CurrentUICulture; 3 CultureInfo enUsCultureInfo = new CultureInfo("en-US"); 4 foreach (var family in Fonts.SystemFontFamilies) 5 { 6 foreach (var keyPair in family.FamilyNames) 7 { 8 var specificCulture = keyPair.Key.GetSpecificCulture(); 9 if (specificCulture.Equals(currentCulture) || specificCulture.Equals(enUsCultureInfo)) 10 { 11 if (keyPair.Key != null && !string.IsNullOrEmpty(keyPair.Value)) 12 { 13 str.Append(keyPair.Value); 14 str.AppendLine(); 15 } 16 } 17 } 18 } 19 ContentTextBlock.Text = str.ToString();
注:有些电脑因系统缺陷或者系统更新冲突,导致System.Windows.Media.Fonts引用失败。所以可以加个异常捕获处理。