![]() |
|
[.NET] Import Custom Font's via Ressources - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Import Custom Font's via Ressources (/showthread.php?tid=3780094) |
Import Custom Font's via Ressources - Ap - Sep 29, 2013 [Import Custom Font's via Ressources]
This can come in handy when you want to use a custom font, but your app needs to run without admin rights (because of ClickOnce or other least privileged requirements). Without admin rights you cannot install fonts on a system. With this tutorial allows you too import a font file straight from your applications ressources without any worries of user's needing the fonts installed! 1. Create Module The Module Can be Named Whatever You Want it to be Named! Module Created by :: MATTHEW KLEINWAKS [img]http://www.winsocketdotnetworkprogramming.com/xmlwebservicesaspnetworkprogramming11chap_files/xmlwebservicesasprogramming215.png[/img] 2. Open and Replace the Module With the Following Code Replace "DIGITALDREAMNARROW" With the Name of The Font Will be Using. ex: Open_Sans Make Sure it's The Same Name (Case Sensitive) as The File You Will Be Creating in Step #3 Code Imports System.Drawing.Text3. Adding the Font File to Your Ressources, ex: Open_Sans Make sure once again that it is the same name as in Step #2 (Case Sensitive) I know there are multiple ways of adding resources, I prefer this method! [img]http://static.daniweb.com/images/attachments/3/img1.jpg[/img] [img]http://pad1.whstatic.com/images/thumb/8/83/Save-File-from-Your-Resources-in-Vb.Net-Step-6.jpg/550px-Save-File-from-Your-Resources-in-Vb.Net-Step-6.jpg[/img] 4. Change Font's on Your Labels! NameOfClass.GetInstance(FONT_SIZE, FONT_TYPE) Code Label1.Font = CustomFont.GetInstance(12, FontStyle.Bold)* - Only3 - Sep 29, 2013 from file Dim pfc As New Drawing.Text.PrivateFontCollection() pfc.AddFontFile("C:\Font.ttf") Font = New Font(pfc.Families(0), 10, FontStyle.Regular) * - Ap - Sep 29, 2013 (Sep 29, 2013 09:21 PM)Only3 Wrote: from file Yes but this way you need your separate file while this way it all-in-one. No need for third party directory! * - Only3 - Sep 29, 2013 try this Dim res = My.Resources.font Dim pfc As New Drawing.Text.PrivateFontCollection pfc.AddMemoryFont(System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(res, 0), res.Length) Font = New Font(pfc.Families(0), 10, FontStyle.Regular) |