I am trying to embed a True Type font into one of my applications. The font is "Digital Readout Upright" which can be found at http://www.grsites.com/fonts/. I have read many articles on how to do this, and when I use this code it dosn't work.
I have the following code:
VB Code:
Public Class Form1 Dim EmbedFonts As New PrivateFontCollection() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim FontStream As IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("EmbedFonts.DIGIREAD.TTF") Dim FontLoc As System.IntPtr = Marshal.AllocCoTaskMem(FontStream.Length) Dim FontData(FontStream.Length) As Byte FontStream.Read(FontData, 0, FontStream.Length) Marshal.Copy(FontData, 0, FontLoc, FontStream.Length) EmbedFonts.AddMemoryFont(FontLoc, FontStream.Length) FontStream.Close() Dim FontStream As IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("EmbedFonts.DIGIREAD.TTF") Dim FontLoc As System.IntPtr = Marshal.AllocCoTaskMem(FontStream.Length) Dim FontData(FontStream.Length) As Byte FontStream.Read(FontData, 0, FontStream.Length) Marshal.Copy(FontData, 0, FontLoc, FontStream.Length) EmbedFonts.AddMemoryFont(FontLoc, FontStream.Length) FontStream.Close() Marshal.FreeCoTaskMem(FontLoc) lblVolume.ForeColor = Color.FromArgb(0, 192, 0) lblVolume.Font = New Font(EmbedFonts.Families(0), 31, FontStyle.Bold) End Sub End Class
My Project name is EmbedFonts, and the font is in the Solution Explorer and the filename is DIGIREAD.TTF. I have DIGIREAD.TTF's Build Property set to Embedded Resource. Also if I look at EmbedFonts.Families(0).Name property it is "Digital Readout Upright".
The font in the the label lblVolume is still arial once the form loads.
Any help would be greatly appreciated!




Reply With Quote