0
votes

How can I set the FontStyle to Condensed Bold ? or Condensed Bold Italic? FontStyle properties does not have other than standard values.

My exact font is: Myriad Pro Font Style: Bold Condensed

How can I create a font based on this truetype?

Note: The font is .OTF OpenType

3
are you using Winforms or WPF - DJ Burb

3 Answers

1
votes

I think something like this should do it.

FontFamily fontFamily = new FontFamily("Condensed Bold");
Font font = new Font(
   fontFamily,
   16,
   FontStyle.Regular,
   GraphicsUnit.Pixel);

To list available font familys (from link in comments)

private void PopulateListBoxWithFonts()
{
    listBox1.Width = 200;
    listBox1.Location = new Point(40, 120);
    foreach ( FontFamily oneFontFamily in FontFamily.Families )
    {
        listBox1.Items.Add(oneFontFamily.Name);
    }
}
0
votes

Use bitwise or to combine FontStyles

FontStyle ItalicBoldUnderline = FontStyle.Italic | FontStyle.Bold | FontStyle.Underline;
0
votes

From a similar answer:

Can you not just use the font name as it appears in the control panel? Most fonts that aren't regular, bold or italic actually have a subfamily type of "regular" anyways. If you download the font properties extensions from Microsoft you can see this on the Names tab. The way the the control panels lists them and the way that .Net knows about them is sometimes different so its a good idea to list out all of the fonts from .Net's perspective:

var installed_fonts = new InstalledFontCollection();
    var families = installed_fonts.Families;
    var allFonts = new List<string>();
    foreach(FontFamily ff in families){
        allFonts.Add(ff.Name);
    }
    allFonts.Sort();
    foreach(String s in allFonts){
        Console.WriteLine(s);
    }

And here's a sample that use Franklin Gothic Demi Cond (which is listed in the CP as "Franklin Gothic Cond Demi")

e.Graphics.DrawString("Test", new Font("Franklin Gothic Demi Cond", 12), new Solid