How to Add a Font in Setup Project
-
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)
-
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)
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 followingPrivate 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 followingPublic 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 -
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)
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
-
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
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