• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1053
  • Last Modified:

VB.NET 2010 Embed Font

I'm trying to figure out how to embed a font into an application.  I don't want the font to be installed on the user's machine, but rather simply be used in a single control on the form.  I've tried numerous "embed font" code snippets only to run into errors with each one.

Any help appreciated.
0
Javin007
Asked:
Javin007
  • 7
  • 3
1 Solution
 
ajb2222Commented:
0
 
Javin007Author Commented:
That is precisely one of the code snippets I checked out that did nothing but produce errors.
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Javin007Author Commented:
I saw it, but I did not try it for the following reason:


My question:

"I don't want the font to be installed on the user's machine..."


That demo:

"The steps we will do here for the demonstration are:
"Install the font
0
 
Éric MoreauSenior .Net ConsultantCommented:
you need to install it on your development PC but not on other PCs
0
 
Javin007Author Commented:
This project is in C#.  I don't have any C# IDEs installed on my system.
0
 
Éric MoreauSenior .Net ConsultantCommented:
you can take FontEmbedding.dll from my zip file!
0
 
Javin007Author Commented:
I came up with a method on my own:

Imports System.Drawing.Text
Imports System.Runtime.InteropServices

Public Class FontResource
    Private PFC As PrivateFontCollection = Nothing

    Public Sub New(ByVal Res() As Byte)
        LoadFont(Res)
    End Sub

    Public ReadOnly Property GetInstance(ByVal Size As Single, ByVal style As FontStyle) As Font
        Get
            If PFC Is Nothing Then Return Nothing
            Return New Font(PFC.Families(0), Size, style)
        End Get
    End Property

    Public Function LoadFont(ByVal Res() As Byte) As Boolean
        Try
            PFC = New PrivateFontCollection
            Dim fontMemPointer As IntPtr = Marshal.AllocCoTaskMem(Res.Length)
            Marshal.Copy(My.Resources.VeraMono, 0, fontMemPointer, Res.Length)
            PFC.AddMemoryFont(fontMemPointer, Res.Length)
            Marshal.FreeCoTaskMem(fontMemPointer)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class


Then call the resource by:

        Dim fnt As New FontResource(My.Resources.VeraMono)
        txtSQL.Font = fnt.GetInstance(8, FontStyle.Regular)


If anyone sees a problem with this method, please let me know.
0
 
Javin007Author Commented:
Correction... While this method throws no errors, and does change the size of the text, it does not actually use the embedded font.  >:(
0
 
Javin007Author Commented:
Grr.  As it turns out, Textboxes have no "UseCompatibleTextRendering" property.  Still looking for suggestions.
0
 
Javin007Author Commented:
No valid answers given.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now