C# 获取所有可用的 FontFamily

发布于 2024-10-22 21:44:59 字数 214 浏览 0 评论 0原文

我有一个输入框,人们在其中输入字体,它会将他们输入的内容保存为 JPEG。一切正常。但是,当他们输入“times new roman”之类的字体名称时,必须将其正确大写为“Times New Roman”,否则将无法工作!

我可以以某种方式迭代所有可用的字体并将其作为下拉列表呈现给他们,这样就不存在拼写问题,并且他们肯定只会在系统上使用字体吗?

I have an input box, and people type a font in and it saves what they type as a JPEG. All works fine. But when they type a font name like 'times new roman' it has to be capitalised properly to 'Times New Roman' or it wont work!

Can I just iterate all the available fonts somehow and present it to them as a dropdown list so there are no spelling problems and they definitely will only be using fonts on the system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只有一腔孤勇 2024-10-29 21:44:59

只需使用下一个代码:

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

Simply use next code:

FontFamily[] ffArray = FontFamily.Families;
foreach (FontFamily ff in ffArray)
{
    //Add ff.Name to your drop-down list
}
〗斷ホ乔殘χμё〖 2024-10-29 21:44:59

或者您可以直接绑定到它:

Or you can just bind to it directly:

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

不乱于心 2024-10-29 21:44:59

我的应用程序中的几个地方都有字体列表,所以我喜欢
加载列表一次并重新使用该列表来绑定到控件。

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

}

I have font lists in several spots within my application so I like to
load 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;       

}
雅心素梦 2024-10-29 21:44:59

这与加里的答案几乎相同,但更紧凑:

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

This is pretty much the same as Gary's answer but a little more compact:

public static readonly List<string> FontNames = FontFamily.Families.Select(f => f.Name).ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文