-
Sep 29th, 2011, 11:11 PM
#1
Using fonts in your project that are embedded in resources
A while back I wanted a way to just put font files in my project resource and be able to use them in my project, so I came up with this:
Also keep in mind that I wrote this a while ago ... so this may be able to be done better...
To Implement:
vb Code:
'At begining of project call this: clsText.installAllFontsFromResources() 'To show something using the font from cache: Button1.Font = clsText.FontFromCache(New Drawing.Font("Font name", 72, Drawing.FontStyle.Bold)) 'If your Button1's font was already set to "Font Name" on your computer before deployment you should also be able to use something like: Button1.Font = clsText.FontFromCache(Button1.Font) 'If you want to change all controls fonts on a form from cache you can do something like this: Dim ctl As Control = Me.GetNextControl(Me, True) Do Until ctl Is Nothing ctl.Font = clsText.FontFromCache(ctl.Font) ctl = Me.GetNextControl(ctl, True) Loop
LIMITATIONS
Any form/control etc that has been created PRIOR to calling "clsText.installAllFontsFromResources()" will not be able to have their font set this way.. it is recommended that you create a class with a shared Main function in it if you wish to use this class (as can be seen in the example project)
Hope this helps some people ...
Also please provide feedback and say thanks if this helped you
LINK DOWN - Downloads
*Downloads are now hosted on multiupload due to the attachment limit on VBForums
Kris
Last edited by i00; Feb 19th, 2013 at 05:43 AM.
-
Oct 2nd, 2011, 02:04 PM
#2
Re: Using fonts in your project that are embedded in resources
Nice, a couple of suggestions though...
- Don't use LCase(xItem.Name), use xItem.Name.ToLower(), and same with all the other LCases.
- You can save the entire hassle by using the My.Resources.* syntax and adding them to the collection manually at the start; maybe you don't have the convenience of automatically loading the fonts, but it will be several orders of magnitude faster (no reflection, no exceptions, no casting, interop...)
-
Oct 2nd, 2011, 06:17 PM
#3
Re: Using fonts in your project that are embedded in resources
Yea i know about both of these ... made this a few years ago and haven't changed it since!
With your second point ... i did it this way because i didn't want to have to specify which resources were fonts and register them all individually ... would their be another way to pick up if they were a font, and if they are then add them, thus avoiding the issue?
Kris
-
Oct 2nd, 2011, 08:57 PM
#4
Re: Using fonts in your project that are embedded in resources
Updated... with a test project - also changed the lcase's to .tolower's
Kris
-
Oct 2nd, 2011, 09:06 PM
#5
Re: Using fonts in your project that are embedded in resources
I don't think there's another way, no. It's too bad.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|