Hi there.

I've for the past few days been experimenting with the use of non system
fonts via the PrivateFontCollection.AddFontFile() method.

If i do something like this:
private void button1_Click(object sender, System.EventArgs e)
{
System.Drawing.Text.PrivateFontCollection pfc = new
System.Drawing.Text.PrivateFontCollection();
pfc.AddFontFile("FREE3OF9.TTF");

FontFamily fam = new FontFamily("Free 3 of 9", pfc);
Font f = new Font(fam, 10F);
this.listBox1.Items.Add(f);
}

and clicks the button about 5 times or so, the font objects get messed up
and thrwos an exception in, among others, the name property.

Any suggestions?

Re: Possible bug using non system fonts by Chris

Chris
Wed Feb 16 16:11:12 CST 2005

What exception?

Each time you click the button, it creates a NEW font collection. Is
that what you intend? What if you declared the pfc variable in a
global location and only instantiate it once?

Just some random thoughts

Chris


Re: Possible bug using non system fonts by ThomasRenSidor

ThomasRenSidor
Wed Feb 16 16:27:07 CST 2005

Actually I've just solved the problem some hours ago. I didn't know that the
font objects needed the FontCollection, so I only declared the FontCollection
locally, and when it got out of scope and got collected by the garbage
collector - the font objects got messed up.

But thanks for the suggestions.

Best regards
Thomas Rene Sidor

"Chris Dunaway" wrote:

> What exception?
>
> Each time you click the button, it creates a NEW font collection. Is
> that what you intend? What if you declared the pfc variable in a
> global location and only instantiate it once?
>
> Just some random thoughts
>
> Chris
>
>