C# Get font family when know font's name

4.1k views Asked by At

I have PrivateFont is declare like this

 PrivateFont = new PrivateFontCollection();
        string[] fontFiles = this.GetFontFiles();
        foreach (string fontFile in fontFiles)
        {
            PrivateFont.AddFontFile(fontFile);
        }

Then I get font info by index:

Font = new Font(PrivateFont.Families[2], 16);

Now, I want get font family by font name. How can I do?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

one way possible is (as I think your question)

var font = PrivateFont.Families
                     .Where(c => c.Name == "Arial")
                     .FirstOrDefault();