Results 1 to 12 of 12

Thread: Deploying a VB.NET Application with a font?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Deploying a VB.NET Application with a font?

    Hi Guys

    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.

    Code:
     newPDF.addTrueTypeFont("..\resources\" & fontName & ".ttf", fontName)
    Many thanks

    Regards Barra.

  2. #2
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: Deploying a VB.NET Application with a font?

    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:
    Code:
    newPDF.addTrueTypeFont(fontName & ".ttf", fontName)
    Since it always will be in the same folder as the executable.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    Many thanks for the reply Zeelia

    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,ll try the other way you mentioned also

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    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

    Many Thanks

  5. #5
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: Deploying a VB.NET Application with a font?

    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).

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    Oh cool

    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
    Attached Files Attached Files
    Last edited by Barrabutus; Aug 5th, 2011 at 09:33 AM.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    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

    Many Thanks

  8. #8
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: Deploying a VB.NET Application with a font?

    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.

    To use a custom font, you need to use the PrivateFontCollection.
    You can find more info about it on the following link or google.
    http://www.java2s.com/Code/VB/2D/Loa...romttffile.htm

    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
    Last edited by Zeelia; Aug 5th, 2011 at 09:28 AM.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    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.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    Would it work if i chose Build Action as Embedded Resource?

    Many Thanks for the replys

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    132

    Re: Deploying a VB.NET Application with a font?

    Hiya !

    pfc.AddFontFile(My.Resources & "DS-DIGII.TTF")

    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

  12. #12
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: Deploying a VB.NET Application with a font?

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width