C# 獲取系統(tǒng)字體的示例代碼
更新時間:2020年07月15日 10:25:29 作者:唐宋元明清2188
這篇文章主要介紹了C# 獲取系統(tǒng)字體的方法,文中講解非常細致,幫助大家更好的理解和學習,感興趣的朋友可以了解下
獲取已安裝的所有字體列表
System.Drawing.FontFamily
StringBuilder str = new StringBuilder(2000); InstalledFontCollection fonts = new InstalledFontCollection(); foreach (FontFamily family in fonts.Families) { str.Append(family.Name); str.AppendLine(); } ContentTextBlock.Text = str.ToString();
獲取區(qū)域語言字體列表
System.Windows.Media.FontFamily
StringBuilder str = new StringBuilder(2000); CultureInfo currentCulture = CultureInfo.CurrentUICulture; CultureInfo enUsCultureInfo = new CultureInfo("en-US"); foreach (var family in Fonts.SystemFontFamilies) { foreach (var keyPair in family.FamilyNames) { var specificCulture = keyPair.Key.GetSpecificCulture(); if (specificCulture.Equals(currentCulture) || specificCulture.Equals(enUsCultureInfo)) { if (keyPair.Key != null && !string.IsNullOrEmpty(keyPair.Value)) { str.Append(keyPair.Value); str.AppendLine(); } } } } ContentTextBlock.Text = str.ToString();
注:有些電腦因系統(tǒng)缺陷或者系統(tǒng)更新沖突,導致System.Windows.Media.Fonts引用失敗。所以建議加個異常捕獲處理。
以上就是C# 獲取系統(tǒng)字體的示例代碼的詳細內容,更多關于c# 獲取字體的資料請關注腳本之家其它相關文章!