Menu

#155 Loading custom fonts

v1.0_(example)
open
nobody
None
5
2022-10-28
2022-10-28
No

Im using zedgraph in a csharp page to generate a graph. I'd like to try to make it load a custom font (a .ttf file) to use as the font.

This is running in an environment in which I do not have access to the standard windows fonts directory. In fact, the only font installed on this machine is courier (yuck).

How do I make zedgraph use a font that is not in my c:\windows directory

I've looked at microsoft's PrivateFont Collection https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-create-a-private-font-collection?view=netframeworkdesktop-4.8&redirectedfrom=MSDN and thats close to what I want. but I don't know what do after I create a privateFontCollection. all I did was :

// i've tried the below in a using statement, too but no love
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
 string fontsDir = LocateDirectory("fonts") + @"\";
 privateFontCollection.AddFontFile(fontsDir + "PLAYBILL.ttf"); // playbill not installed on local machine

 using (ZedGraphControl zedGraph = new ZedGraphControl())
 {
     zedGraph.GraphPane = new GraphPane();
     zedGraph.GraphPane.Title.Text = title;
     zedGraph.GraphPane.Title.FontSpec = new FontSpec("Playbill", 16, Color.Black, true, false, false); // the font is always the default, not the one i want.
     zedGraph.GraphPane.Title.FontSpec.Border = new Border(false, Color.White, 0);
     // other zedgraph stuff goes here, but the last line renders it to a file.
 }

So? how do you load a new font so ZedGraph can see it

Discussion


Log in to post a comment.