Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't want to install "MyFontAreal.ttf" in windows font folder because i have define "MyFontAreal.ttf" in resources folder in dll file. Any possibility without install.

What I have tried:

VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MyControl.Font = MyControl.GetSymbology(RabtaysoftSize, FontStyle.Regular)
    End Sub

'************* Call Dll property ****************

Public ReadOnly Property GetSymbology(ByVal Size As Single, ByVal style As FontStyle) As Font
        Get
            'IF THIS IS THE FIRST TIME GETTING AN INSTANCE
            'LOAD THE FONT FROM RESOURCES
            If _pfc Nothing Then LoadMyFnontAreal()

            'RETURN A NEW FONT OBJECT BASED ON THE SIZE AND STYLE PASSED IN
            Return New Font(_pfc.Families(0), Size, style)
        End Get
    End Property

    Public Property StartingIndex128 As Integer

    Private Sub LoadMyFnontAreal()
        Try
            'INIT THE FONT COLLECTION
            _pfc = New PrivateFontCollection

            'LOAD MEMORY POINTER FOR FONT RESOURCE
            Dim fontMemPointer128 As IntPtr = Marshal.AllocCoTaskMem(My.Resources.MyFontAreal.Length)
            'COPY THE DATA TO THE MEMORY LOCATION

            Marshal.Copy(My.Resources.MyFontAreal, StartingIndex128, fontMemPointer128, My.Resources.MyFontAreal.Length)

            'LOAD THE MEMORY FONT INTO THE PRIVATE FONT COLLECTION
            _pfc.AddMemoryFont(fontMemPointer128, My.Resources.MyFontAreal.Length)

            'FREE UNSAFE MEMORY
            Marshal.FreeCoTaskMem(fontMemPointer128)

        Catch ex As Exception
            'ERROR LOADING FONT. HANDLE EXCEPTION HERE
        End Try
    End Sub
Posted
Updated 28-Jun-19 1:28am
v2

1 solution

Yet another repost of the same question ... the answer isn't going to change, no matter how many times you post it ...
Use TTF file in resources folder or in DLL file[^]
Use TTF file in resources folder or in DLL file[^]
Without installation TTF use from DLL[^]
 
Share this answer
 
Comments
Maciej Los 2-Jul-19 11:18am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900