AddFontResourceEx() in C#

S

Simon Jefferies

Hi there,

I'm trying to use a font registered by calling AddFontResourceEx(). The
function returns one to indicate its registered, but when calling new
Font() it substitutes it for Microsoft Sans Serif.

Here's my code:-

private const int FR_PRIVATE = 0x10;
private const int FR_NOT_ENUM = 0x20;

[DllImport("gdi32.dll")]
static extern int AddFontResourceEx(string lpszFilename, uint fl, IntPtr
pdv);

int res = AddFontResourceEx(_Filename, FR_PRIVATE, IntPtr.Zero);

How do I use this font?

Cheers,
Simon.
 
N

Nicholas Paldino [.NET/C# MVP]

Simon,

If you are looking to use a private font, then why not use the
PrivateFontCollection class? You can call the AddFontFile method to add a
font to the private collection, and then use it in your app.

Or do you have a specific need to get the handle through the P/Invoke
layer?
 
S

Simon Jefferies

Nicholas said:
Simon,

If you are looking to use a private font, then why not use the
PrivateFontCollection class? You can call the AddFontFile method to add a
font to the private collection, and then use it in your app.

Or do you have a specific need to get the handle through the P/Invoke
layer?

Thanks for your reply,

I wasn't aware of this class. From the looks of it this class does what
I need, as i need a list of fonts that have been added too. I'll give it
a go.

Thanks!! :)
Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top