[System.Runtime.InteropServices.DllImport("gdi32.dll")] private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, ref uint pcFonts);
try
{
string resource = "LEDFont.ttf"; // specify embedded resource name
// receive resource stream
System.IO.Stream fontStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
// create an unsafe memory block for the font data
System.IntPtr data = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)fontStream.Length);
// create a buffer to read in to
byte[] fontdata = new byte[fontStream.Length];
// read the font data from the resource
fontStream.Read(fontdata, 0, (int)fontStream.Length);
// copy the bytes to the unsafe memory block
System.Runtime.InteropServices.Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
///IMPORTANT line to register font in system
uint cFonts = 0;
AddFontMemResourceEx(data, (uint)fontdata.Length, IntPtr.Zero, ref cFonts);
// pass the font to the font collection
pFC.AddMemoryFont(data, (int)fontStream.Length);
// close the resource stream
fontStream.Close();
// free up the unsafe memory
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(data);
lblTaktTime.Font = new Font(pFC.Families[0], 60, FontStyle.Bold);
}
catch (Exception exp)
{
}