3

我维护的一个 WinForms 应用程序在一小部分用户机器上崩溃(迄今为止可能大约 4 台)。对于这些用户,应用程序每次都会崩溃,并且在显示第一个对话框之前就崩溃了。

例外

Source:
System.Drawing

Message:
Font 'Arial Black' does not support style 'Bold'.

Stack Trace:
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet)

应用程序使用的字体之一是 Arial Black:

this.label3.Font = new System.Drawing.Font("Arial Black", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

第一次发生这种崩溃时,我注意到用户计算机上有一种字体,但不是我的。它被称为“Arial Black Italic”,日期为 1997 年。这是文件名:

ARBLI___.TTF

enter image description here

用户有 Windows XP。

我删除了字体,之后应用程序运行良好。正如我所提到的,在过去的 22 个月中,这次崩溃发生在大约 3 个其他用户身上。每次从用户计算机中删除“Arial Black Italic”字体似乎都能解决问题。

The most recent time, the user had Windows 7 and the font was date much newer, yet the aforementioned protocol still resolved the problem.

At this point, I am trying to figure out the root cause of this crash bug and how to prevent it.

4

1 回答 1

0

尝试这样的事情。

using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Create regular font first.
            // Depending on the user's system, this font may already be bold.
            //

            var theFont = new System.Drawing.Font(
                "Arial Black",
                8.25F,
                System.Drawing.FontStyle.Regular,
                System.Drawing.GraphicsUnit.Point,
                ( ( byte )( 0 ) )
                );

            // If font is not bold, then try to create it.
            //

            if ( ( null != theFont ) && !theFont.Bold )
            {
                if ( theFont.FontFamily.IsStyleAvailable( FontStyle.Bold ) )
                {
                    theFont = new Font( theFont, FontStyle.Bold );
                }
            }

            // Now use the font.
            //

            this.label3.Font = theFont;
        }
    }
}
于 2012-06-01T19:25:07.537 回答