Arial黑色斜体字体导致WinForms应用程序崩溃

Arial黑色斜体字体导致WinForms应用程序崩溃,winforms,fonts,Winforms,Fonts,我维护的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.Initi

我维护的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黑色:

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年。这是文件名:

阿布里

用户使用的是Windows XP

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

最近一次,用户使用的是Windows7,字体更新了很多,但是前面提到的协议仍然解决了这个问题


在这一点上,我正试图找出这个崩溃错误的根本原因以及如何防止它。试试这样的方法

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;
        }
    }
}