How to install a font on a user computer in VB.NET so that applications like Word can use it?

You must install the font on all user machines that will use the application that I am writing, which creates its own documents in Word. This is a barcode font.

I successfully added the font to my solution and installed its assembly action in the Embedded Resource and also successfully wrote the code to check if the font is installed on the user system.

Now I just need to figure out how to extract the font from my solution and install it on the user computer, as if they installed the font itself for use in Office applications, etc.

In most of the examples that I found, to use a font in a VB.NET application instead, and the one I found that seems to fit my purpose does not work for me.

+5
source share
4 answers

Copy the font to the Windows font folder, and then you need to add the font to the registry. I have not tried this myself, but I think it can be done by opening the font using ShellExecuteAapi in the same way as shown here .

You can use vbscript here, which can be useful as a starting point, since you can use similar syntax and functions in VB.Net: Hello, Script! How to install fonts using Script?

+2

Windows\Fonts ( , Environment.GetFolderPath , .NET Framework Windows, , - ).

AddFontResource, . AddFontResource Windows API, P/Invoke VB.NET. ( lpszFilename - , ):

<DllImport("gdi32.dll"), CharSet := CharSet.Auto> _
Public Shared Function AddFontResource(ByVal lpszFilename As String) As Integer

, Word ( , ) , AddFontResource , , . , WM_FONTCHANGE SendMessage hWnd HWND_BROADCAST. , P/Invoke; :

Public Const HWND_BROADCAST As Integer = &HFFFF
Public Const WM_FONTCHANGE As Integer = &H1D

<DllImport("user32.dll"), CharSet := CharSet.Auto> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer

:

SendMessage(New IntPtr(HWND_BROADCAST), WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero)

. Windows. , , . :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
+10

First, you copy the font to the Windows font folder, and then call AddFontResource with p / invoke.

Here is an example, this is in C #, but you should be able to:

UPDATE

New URL

http://brutaldev.com/post/2009/03/26/Installing-and-removing-fonts-using-C.aspx

+3
source

I used the installer project to install the fonts that I need with my application and followed this guide

0
source

All Articles