Custom font styles with graphics
I have the following list of fonts:
I have no issues with using them via
new Font("XXXX Sans", 21, FontStyle.Bold, GraphicsUnit.Pixel)
However, what do i do when i need to use a non-standard font style like light? All t开发者_JAVA百科hat is provided is an enumeration and that is not suitable.
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 SolidBrush(Color.Red), 25, 25);
精彩评论