Im wondering if anyone would be able to point me to a very well detailed tutorial as to how to Embed a font into my deployed application , So when its installed on an end user,s computer, they can see the font.
I currently have this code and have embedded the font.ttf into the resource under the files option.
There are different approaches as for how to do this.
The most simple would be to include it as a resource, as you have done. And then deploy your application with ClickOnce. It automatically takes care of all files and creates a package/setup file for you.
If you want to manually handle the file, go to the solution explorer, right click on your project name (eg. WindowsApplication1) and choose Add -> Existing file...
Then you choose your TTF file and it will appear in the solution explorer.
Click the TTF in the solution explorer and choose
Build Action: None
Copy to Output Directory: Copy always / Copy if newer.
Now you will always have the TTF file in the same folder as your executable.
*EDIT* The latter option would allow you to do this to use your font:
I have tried to add a ttf as a resource file and then installed it on my laptop and it gives me a JIT Debugger error cannot find resource file.
The logo i added as an image resource works fine i checked the resources folder after installing the application and the logo is there but the TTF is not.
I tried the second way but when installed it again on the laptop i checked the install directory to see if arial.ttf was inside but it wasnt and i had the settings as you described so its almost like it ignored the font completely.
I,ll try a new project specifically to perform this
Hiya!
If you add the TTF as a resource file, you would have to use My.Resources to access the file, using "..\resources\file.ttf" will not work because when you add a file as a resource, your application doesn't create the resources folder when you deploy it, it embeds the resources with the help of the file Resources.resx (I think).
I,ll try again and use My.Resources & fontName & ".ttf" as a location
But when i tried the click once deployment and then installed it, it didnt bring the ttf file with the executable at all, The jpg i embedded did come across and i could find it in the Resources folder of my app but the ttf file was nowhere to be found :S
Im just doing a new basica project to attempt this I have 1 textfield and 1 button with this code.
Code:
'This is an LCD looking font.
Dim newFont As New Font("DS-DIGII.TTF", 16)
TextBox1.Font = newFont
For i As Integer = 0 To 10000
TextBox1.Text = i
Application.DoEvents()
Next
But am still having problems to get it to use the font without physically installing it into windows
EDIT** Ive attached the actual project containing the above code so you can see exactly what ive done with it and hopefully point out whats going wrong
Really appreciate your help
Many Thanks
Last edited by Barrabutus; Aug 5th, 2011 at 09:33 AM.
Ok seems ive found the way to use it in the project without installing it
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("Path To Font")
' I found with the DS-DIGII.ttf i had to change to fontstyle.italic because the font did not support regular
TextBox1.Font = New Font(pfc.Families(0), 46, FontStyle.Italic)
For i As Integer = 0 To 10000
TextBox1.Text = i
Application.DoEvents()
Next
End Sub
Now to build an Exe and try to transfer this to my laptop
The problem lies in how you are trying to use the TTF file, you can't tell it to use .Font("My_Font.ttf", 16) because then it will look in the installed fonts of windows.
Also, please delete the bin folder when uploading a project to the forums as this is prohibited.
*EDIT* Haha seems like you were faster than me. Anyhow, mark the thread resolved if you think that it is.
Go to the top of the thread and use the menu Thread Tools -> Mark Thread Resolved
Oh sorry its the first time ive uploaded a project and didnt realise about the Bin folder,
I,ll delete the attachment if i can and reup a new one without the Bin folder
I found a link about the privateFontCollection and that seems to work fine now im just trying to figure out how to "bundle" the ttf file with the application.
ive tried Application.StartUpPath & "\DS_DIGII.TTF" as a path but no joy with that
EDIT ** I changed the uploaded Project Folde to not include the Bin directory now or at leats i think it shouldnt be there lol
Many Thanks
Last edited by Barrabutus; Aug 5th, 2011 at 09:34 AM.
This generates an Error Resources is a namespace.
If i add another . after resources i can see the DS-DIGII and DS_DIGIT but they have no File extensions.
So i tried to append the .TTF like so
pfc.AddFontFile(My.Resources.DS_DIGII & ".TTF")
And this results in
Operator '&' is not defined for types '1-dimensional array of Byte' and 'String'.
Something that sounds so easy is rather hard.... lol
Hi!
You actually can't get this type of resource from My.Resources.
Try using My.Resources.ResourceManager.GetObject("DS-DIGII") but I don't know if it works.
I've seen many threads about this though so if you search the forums, you will surely find some working code and explanations.
As for post #9 where I assume you are trying the method that's deploying without ClickOnce:
You can't actually "bundle" the TTF file into your executable, you have to ship/deploy your application together with the necessary files, just as when you are referencing a DLL, you will have to deploy it with your executable. However, since you enabled the option "Copy to output..." on the TTF file, it should be copied to the same folder as your executable thus enabling you to reference it as "DS-DIGII.ttf" only, no need to write path.