2012-04-24 12 views
3

ユーザーマシンのごく一部でクラッシュするWinFormsアプリケーション(おそらく約4つまで)。これらのユーザーのたびにアプリケーションがクラッシュし、最初のダイアログが表示される前にクラッシュします。アプリケーションが使用するフォントのWinFormsアプリケーションのクラッシュを引き起こすArial Black Italicフォント

例外

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の黒斜体」と呼ばれていた、それはこれがファイル名だった1997年に日付を記入した。

ARBLI ___ TTFユーザーがWindows XPを持っていた

enter image description here

フォントを削除したあと、アプリケーションが正常に実行されました。私が言及したように、過去22ヶ月間に、このクラッシュは約3人の他のユーザーに起こりました。ユーザーのコンピュータから「Arial Black Italic」フォントを削除するたびに、問題が解決されたようです。

最新の時刻に、ユーザーはWindows 7を使用していましたが、そのフォントはもっと新しいものでしたが、上記のプロトコルでは依然として問題が解決されました。

この時点で、私はこのクラッシュバグの根本原因とその防止方法を解明しようとしています。

答えて

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; 
     } 
    } 
} 
関連する問題