font install

hi

I use a special font in my app with textbox and drawstring methods.

How can I install this font with the apllication

i tried to copy the fontfile to windows\fonts folder but even on restart the font does not show up until I manually open the fonts folder and click on the font



Answer this question

font install

  • Jazz Soft

    Try using the PrivateFontCollection class, it allows you add a font from a file.

  • khan2025

    Edited, improved and updated private font info and code at my other thread.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=542664&SiteID=1

    (original hack removed)



  • AlexSok

    (Edited Reply) Experts, is there a way to shorten this code

    Imports System.Drawing

    Imports System.Runtime.InteropServices

    Public Class Form1

    Public privateFontCollection As New Drawing.Text.PrivateFontCollection

    Public FamilyName As String

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' Name embedded resource font file

    Dim m As New System.IO.MemoryStream(My.Resources.PENMP___)

    Dim fontStream As IO.Stream = m

    Dim data As System.IntPtr = Marshal.AllocCoTaskMem(fontStream.Length)

    'create a buffer to read in to

    Dim fontdata() As Byte

    ReDim fontdata(fontStream.Length)

    'fetch the font program from the resource

    fontStream.Read(fontdata, 0, fontStream.Length)

    'copy the bytes to the unsafe memory block

    Marshal.Copy(fontdata, 0, data, fontStream.Length)

    'pass the font to the font collection

    privateFontCollection.AddMemoryFont(data, fontStream.Length)

    'close the resource stream

    fontStream.Close()

    'free the unsafe memory

    Marshal.FreeCoTaskMem(data)

    FamilyName = privateFontCollection.Families(0).Name

    TextBox1.Font = New Font(FamilyName, 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

    End Sub

    End Class



  • rdrast

    hi,

    Is your problem solved

    Thank you,
    Bhanu.



  • Aryan_Patel_05

    Hi is this thread still alive I'd like to comment on it..

    I was having the same issue as Dewald was describing, I tested the code examplesubmitted by Tall Dude, but it is not working for me. At runtime the variable 'FamilyName' shows the name of my embedded font, but "Sans Serif" is the font actually being assigned to my control by the Font constructor.

    Thanks,

    Oyvind


  • LittleNew

    Thank you for your reply.I have tried it before without sucsess.I will try it again.

    Do you know if a font in the privateFont Collection can be used in a rich text editor, textbox and with the drawString method


  • font install