【问题标题】:Arial Black Italic font causing WinForms application to crashArial Black Italic 字体导致 WinForms 应用程序崩溃
【发布时间】:2012-04-24 18:20:29
【问题描述】:

我维护的一个 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

用户使用的是 Windows XP。

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

最近一次,用户使用的是 Windows 7,并且字体日期较新,但上述协议仍然解决了问题。

此时,我正试图找出这个崩溃错误的根本原因以及如何防止它。

【问题讨论】:

    标签: winforms fonts


    【解决方案1】:

    试试这样的。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 2015-10-21
      • 2016-06-04
      • 2011-08-24
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多