Solved

VB.NET 2010 Embed Font

Posted on 2010-09-17
11
1,038 Views
Last Modified: 2013-11-26
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
Comment
Question by:Javin007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 6

Expert Comment

by:ajb2222
ID: 33702796
0
 
LVL 4

Author Comment

by:Javin007
ID: 33703021
That is precisely one of the code snippets I checked out that did nothing but produce errors.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33703030
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 4

Author Comment

by:Javin007
ID: 33703341
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33703380
you need to install it on your development PC but not on other PCs
0
 
LVL 4

Author Comment

by:Javin007
ID: 33703630
This project is in C#.  I don't have any C# IDEs installed on my system.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33703700
you can take FontEmbedding.dll from my zip file!
0
 
LVL 4

Accepted Solution

by:
Javin007 earned 0 total points
ID: 33703962
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
 
LVL 4

Author Comment

by:Javin007
ID: 33704398
Correction... While this method throws no errors, and does change the size of the text, it does not actually use the embedded font.  >:(
0
 
LVL 4

Author Comment

by:Javin007
ID: 33704456
Grr.  As it turns out, Textboxes have no "UseCompatibleTextRendering" property.  Still looking for suggestions.
0
 
LVL 4

Author Closing Comment

by:Javin007
ID: 34078567
No valid answers given.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question