Connecting Tech Pros Worldwide Forums | Help | Site Map

embed font in vb2005 application

scott.mankowitz@verizon.net
Guest
 
Posts: n/a
#1: Mar 16 '06
Hi!

Does anyone know if there is an easy way to embed fonts into a vb2005
application? Ideally, I would like to add the .ttf files as resources
and just set the font using the forms designer. I can't seem to do
that.

I also tried to include the font as a resource and do this:

This is part of the form_load sub
dim ffjeopardy as fontfamily
dim lbljeop as label



ffJeopardy = AddFont(My.Resources.gyparody)

lblJeop.Font = New Font(ffJeopardy, 48, FontStyle.Regular,
GraphicsUnit.Pixel)
btnGO.Font = lblJeop.Font
btnGO.Invalidate()


The AddFont function looks like this


Public Function AddFont(ByVal resource As Byte()) As FontFamily

'Allocate some memory on the global heap
Dim ptrFont As IntPtr = Marshal.AllocHGlobal(resource.Length)
Marshal.Copy(resource, 0, ptrFont, resource.Length)
PrivateFonts.AddMemoryFont(ptrFont, resource.Length)
Marshal.FreeHGlobal(ptrFont)
Return PrivateFonts.Families(PrivateFonts.Families.Length - 1)

End Function


Closed Thread