2

私は、ある時点で実行時にテキストをフォームに直接描画する VB.NET Windows Forms プロジェクトを持っています。ただし、フォントでペイントする前に、フォントとフォントサイズがユーザーのマシンに存在することを確認したいと思います。そうでない場合は、他の同様のフォントをいくつか試して、最終的に Arial か何かをデフォルトに設定します。

ユーザーのコンピューターでフォントをテストおよび検証する最良の方法は何ですか?

4

4 に答える 4

8

「HowTo:Enumerate Installed Fonts」というタイトルのMSDNの記事から、次のコードを見つけました。



InstalledFontCollection installedFontCollection = new InstalledFontCollection();

// Get the array of FontFamily objects.
FontFamily[] fontFamilies = installedFontCollection.Families;


于 2008-09-20T01:39:34.187 に答える
2

これがc#の1つの解決策です:

public partial class Form1 : Form
{
    public Form1()
    {
        SetFontFinal();
        InitializeComponent();
    }

    /// <summary>
    /// This method attempts to set the font in the form to Cambria, which
    /// will only work in some scenarios. If Cambria is not available, it will
    /// fall back to Times New Roman, so the font is good on almost all systems.
    /// </summary>
    private void SetFontFinal()
    {
        string fontName = "Cambria";
        Font testFont = new Font(fontName, 16.0f, FontStyle.Regular,
            GraphicsUnit.Pixel);

        if (testFont.Name == fontName)
        {
            // The font exists, so use it.
            this.Font = testFont;
        }
        else
        {
            // The font we tested doesn't exist, so fallback to Times.
            this.Font = new Font("Times New Roman", 16.0f,
                FontStyle.Regular, GraphicsUnit.Pixel);
        }
    }
}

そして、これがVBの1つの方法です。

Public Function FontExists(FontName As String) As Boolean

    Dim oFont As New StdFont
    Dim bAns As Boolean

    oFont.Name = FontName
    bAns = StrComp(FontName, oFont.Name, vbTextCompare) = 0
    FontExists = bAns

End Function
于 2008-09-20T01:40:56.367 に答える
1

このコードになるこの同じ質問も参照してください。

    private bool IsFontInstalled(string fontName) {
        using (var testFont = new Font(fontName, 8)) {
            return 0 == string.Compare(
              fontName,
              testFont.Name,
              StringComparison.InvariantCultureIgnoreCase);
        }
    }
于 2008-10-31T14:37:33.730 に答える
0

ArialBoldItalicがフォントになる可能性は低いです。これは、Arialファミリのサブクラスです。

シンプルに保ち、「Arial」をテストしてみてください。

于 2010-10-05T23:19:22.987 に答える