Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Add a Font in Setup Project

How to Add a Font in Setup Project

Scheduled Pinned Locked Moved C#
csharptutorialworkspace
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bajrang Singh
    wrote on last edited by
    #1

    Hi ALL, I need to add a hindi font in my set up project(C#) so that client does not need to install that font seprately. So should I add that font in my project. I copied that font in my setup but it simply get copied to the target machine but doesnot get install itself. Please let me know how could I do this so that it get automatically installed in windows font folder. Thanks a lot

    Bajrang Singh Using .net 2.0 (VS2005)

    R G 2 Replies Last reply
    0
    • B Bajrang Singh

      Hi ALL, I need to add a hindi font in my set up project(C#) so that client does not need to install that font seprately. So should I add that font in my project. I copied that font in my setup but it simply get copied to the target machine but doesnot get install itself. Please let me know how could I do this so that it get automatically installed in windows font folder. Thanks a lot

      Bajrang Singh Using .net 2.0 (VS2005)

      R Offline
      R Offline
      Rupesh Kumar Swami
      wrote on last edited by
      #2

      hi, before some time ago , i face this problem. i find the net to resolve this problem and find solution which i decribe below. Note that following code is in vb.net so convert it in c# first of all add this font to your application for example "ITCKRIST.TTF" now imports following namespace in module or form level Imports System.Drawing Imports System.Text Imports System.Collections.Generic Imports System.ComponentModel now call the following API as following Private Declare Auto Function AddFontMemResourceEx Lib "Gdi32.dll" _ (ByVal pbFont As IntPtr, ByVal cbFont As Integer, _ ByVal pdv As Integer, ByRef pcFonts As Integer) As IntPtr now write a function as following Public Function GetFont(ByVal FontResource() As String) As _ Drawing.Text.PrivateFontCollection 'Get the namespace of the application Dim NameSpc As String = _ Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() Dim FntStrm As IO.Stream Dim FntFC As New Drawing.Text.PrivateFontCollection() Dim i As Integer For i = 0 To FontResource.GetUpperBound(0) 'Get the resource stream area where the font is located FntStrm = _ Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( _ NameSpc + "." + FontResource(i)) 'Load the font off the stream into a byte array Dim ByteStrm(CType(FntStrm.Length, Integer)) As Byte FntStrm.Read(ByteStrm, 0, Int(CType(FntStrm.Length, Integer))) 'Allocate some memory on the global heap Dim FntPtr As IntPtr = _ Runtime.InteropServices.Marshal.AllocHGlobal( _ Runtime.InteropServices.Marshal.SizeOf(GetType(Byte)) * _ ByteStrm.Length) 'Copy the byte array holding the font into the allocated memory. Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, _ FntPtr, ByteStrm.Length) 'Add the font to the PrivateFontCollection FntFC.AddMemoryFont(FntPtr, ByteStrm.Length) Dim pcFonts As Int32 pcFonts = 1 AddFontMemResourceEx(FntPtr, ByteStrm.Length, 0, pcFonts) 'Free the memory Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr) Next Return FntFC End Function almost work is done . Now you can change font of any control. for example

      1 Reply Last reply
      0
      • B Bajrang Singh

        Hi ALL, I need to add a hindi font in my set up project(C#) so that client does not need to install that font seprately. So should I add that font in my project. I copied that font in my setup but it simply get copied to the target machine but doesnot get install itself. Please let me know how could I do this so that it get automatically installed in windows font folder. Thanks a lot

        Bajrang Singh Using .net 2.0 (VS2005)

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        In the setup program click add special folder and choose Fonts Folder. Add your font to that folder. The font will be automatically installed and uninstalled together with your program

        #region signature my articles #endregion

        R 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          In the setup program click add special folder and choose Fonts Folder. Add your font to that folder. The font will be automatically installed and uninstalled together with your program

          #region signature my articles #endregion

          R Offline
          R Offline
          Rupesh Kumar Swami
          wrote on last edited by
          #4

          hi Giorgi, your solution is better from my solution. difference is that my solution is work for specific application ,not for all. thanks

          Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India) My Company

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups