C# Setting FontDialog to only display TrueType fonts

假如想象 提交于 2019-12-05 04:50:35

The FontDialog class already does this, it uses the ChooseFont() API call with the CF_TTONLY option. Which forces the dialog to only display fonts that advertise themselves as TrueType fonts. The links suggests there are fonts around that fool the dialog, never heard of it before until today. Which makes it quite rare but certainly not unexpected, there are lots of junk fonts around with bad metadata.

There isn't anything you can do to catch the exception, it is raised in a callback function that's baked into the .NET framework. Rewriting the class is an option but not a pleasant one. Uninstalling the troublemaker font is certainly the easy solution.

No real nice way around this one except to try/catch block it

try
{
    if (m_FontDialog.ShowDialog(frmMain.mainForm) == DialogResult.OK)
    {
        //Successful
    }
}
catch (Exception ex)
{
    //Not a truetype font
    MessageBox.Show(frmMain.mainForm, ex.Message + Environment.NewLine + "Font not changed.", "Font Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

I'm not sure whether it will work, but try to set FontDialog.AllowSimulations to false.

You can use the custom FontDialog available here to overcome this exception. It is developed in C#.Net.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!