Results 1 to 11 of 11

Thread: Copying/Installing font used in WinForm project

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Copying/Installing font used in WinForm project

    Alright, here's the deal:
    Consider you want to reduce app size therefore you are using a font which contains lots of pretty useful icons plus you are able to change all components color and accents to do cool graphical flexibilities, Like Microsoft "Segoe Fluent Icons". But how about a user with Windows 7 or earlier version of MS Windows operating system (Windows 10 have a similar alternative called "Segoe MDL2 Assets" but still not quite this one.) I looked up all over. What is the correct way to achieve such including-used-fonts-built-in thing in our vb.net winform projects?

    What I've tried:
    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                System.IO.File.WriteAllBytes("c:\windows\fonts\SegoeIcons.ttf", My.Resources.SegoeIcons)
                Application.Restart()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
            End Try
        End Sub
    Which results "Access to path "C:\Windows\Fonts\SegoeIcons.ttf" is denied" exception.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copying/Installing font used in WinForm project

    I've never done it myself but I think that you need to use the PrivateFontCollection class. This allows your app to use fonts that it supplies rather than having them installed in Windows.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Copying/Installing font used in WinForm project

    We add a registry setting via start.

    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Iskoola Pota Bold" /t REG_SZ /d "%WINDIR%\Fonts\iskpotab.ttf" /f
    Please remember next time...elections matter!

  4. #4

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Copying/Installing font used in WinForm project

    (Reply to jmcilhinney)
    It wouldn't create something graphical right? Cause I don't want to engage with these kind of things. I also browsed https://docs.microsoft.com/en-us/dot...orkdesktop-4.8 but nothing much i've learned from it. Can you describe a little more with an actual example?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copying/Installing font used in WinForm project

    Quote Originally Posted by pourkascheff View Post
    It wouldn't create something graphical right? Cause I don't want to engage with these kind of things.
    I have no idea what that means.
    Quote Originally Posted by pourkascheff View Post
    I also browsed https://docs.microsoft.com/en-us/dot...orkdesktop-4.8 but nothing much i've learned from it. Can you describe a little more with an actual example?
    The page you linked to provides an actual example. What don't you understand? You load fonts from files into the collection, you create a Font, you use it. What's the actual problem?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Copying/Installing font used in WinForm project

    Quote Originally Posted by jmcilhinney View Post
    I have no idea what that means.
    Forgive me for my lack of English. What I tried to say is does it turn text to graphical items/shapes or not? Because if yes, I rather not to do such things and stick to code only.

    Quote Originally Posted by jmcilhinney View Post
    The page you linked to provides an actual example. What don't you understand? You load fonts from files into the collection, you create a Font, you use it. What's the actual problem?
    Don't get mad at me sir but I deeply have problem to understand Microsoft articles with a plenty amount of information in a language I don't speak.
    I tried codes in it.

    The remaining question is "How to use a font in a WinForm and run it in another console while it doesn't have the font?"

  7. #7

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Copying/Installing font used in WinForm project

    How about add used font in fonts folder in deploy section to being installed for user?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Copying/Installing font used in WinForm project

    Quote Originally Posted by jmcilhinney View Post
    I've never done it myself but I think that you need to use the PrivateFontCollection class. This allows your app to use fonts that it supplies rather than having them installed in Windows.
    Quote Originally Posted by jmcilhinney View Post
    I have no idea what that means.

    The page you linked to provides an actual example. What don't you understand? You load fonts from files into the collection, you create a Font, you use it. What's the actual problem?
    Quote Originally Posted by pourkascheff View Post
    The remaining question is "How to use a font in a WinForm and run it in another console while it doesn't have the font?"
    You use the PrivateFontCollection that jmcilhinney suggested, and the page you posted a link to, that shows how to use it

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Copying/Installing font used in WinForm project

    Originally Posted by pourkascheff
    The remaining question is "How to use a font in a WinForm and run it in another console while it doesn't have the font?"
    What do you mean by 'another console'?

  10. #10

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Copying/Installing font used in WinForm project

    Quote Originally Posted by .paul. View Post
    What do you mean by 'another console'?
    I mean 'Use a sort of old LCD font on your WinForms application, Run it on another computer which does not have that font.'

    That Learn.Microsoft article turns text strings to graphics. Am I right? I don't want to do so. I have lots of labels and textboxes which should represent the theme.
    What I want to perform is more like what this nerd guy did in deploying app. Well, Instant plug-and-play apps are much better... Do you know an alternative?

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: Copying/Installing font used in WinForm project

    This thread was from just a couple days ago and may help:

    https://www.vbforums.com/showthread....an-application

Tags for this Thread

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