471,325 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

C# Embedded font for button

Hello all,

I've added a font to my project and set it to "Embedded Resource".

I load the font into a global PrivateFontCollection. (InitCustomFont -
shown below)

I then set the font of a label to be equal to the custom font
(SetCustomFont - shown below)

The font size changes but the family doesn't. If I write directly to
the form using Graphics.DrawString the new font is displayed???

Does that mean I can't change the font of labels/buttons etc. to
resource fonts?


private void InitCustomFont()
// Load the resource
Stream fontStream =
this.GetType().Assembly.GetManifestResourceStream( "Graphyx.custom.ttf");

// Create a buffer to read into
byte[] fontData = new byte[fontStream.Length];

// Fetch the font program from the resource
fontStream.Read(fontData, 0, (int)fontStream.Length);

fixed (byte* pFontData = fontData)

// Pass the font to the font collection
// Close the resource stream

private void SetCustomFont()
System.Drawing.Font fn;
FontFamily ff;

ff = pfc.Families[0];

fn = new Font(ff, 16, FontStyle.Regular);

//lblHelp.Font = new System.Drawing.Font("Courier New", 16.0f,
lblHelp.Font = fn;

Feb 8 '06 #1
0 6299

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jim | last post: by
1 post views Thread by Blasting Cap | last post: by
6 posts views Thread by andrew.ames | last post: by
reply views Thread by =?Utf-8?B?Qm9iIFdhaXRl?= | last post: by
4 posts views Thread by DamienS | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.