Hi,
I have come across a strange issue whilst embedding a font into a custom user control. This is the code i used to store the font in order to use it again at runtime.
private PrivateFontCollection pfc;
private void GeneratePrivateFontCollection()
{
Stream fontStream = new MemoryStream(Renishaw.Calibration.RotaryXL.UI.Properties.Resources.digital_7__mono_);
if (fontStream != null)
{
unsafe
{
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);
Byte[] fontdata;
fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata, 0, (int)fontStream.Length);
Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
pfc.AddMemoryFont(data, (int)fontStream.Length);
fontStream.Close();
Marshal.FreeCoTaskMem(data);
}
}
}
private void SetControlFont()
{
FontStyle fs = this.Font.Style;
if (pfc.Families.Length > 0)
{
foreach (FontFamily ff in pfc.Families)
{
if (ff.IsStyleAvailable(FontStyle.Regular) && fs == FontStyle.Regular)
{
m_font = new Font(ff, m_fontSize, FontStyle.Regular);
return;
}
}
}
}
The problem comes when drawing the font in the control
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
Brush readingBrush = new SolidBrush(m_textColor);
g.DrawString(m_reading, m_font, readingBrush, m_location);
readingBrush.Dispose();
}
This all works fine on my PC and another one in the office. However 3 of the PC's for some reason do not use the embedded font. Could anyone think of a reason for this?
Thanks George