What's Here?
- Members: 137,227
- Replies: 481,494
- Topics: 75,061
- Snippets: 2,567
- Tutorials: 675
- Total Online: 2,020
- Members: 103
- Guests: 1,917
|
This is a snippet for embedding a font into an application, which ensures if the user doesn't have the font file installed, it really doesn't matter
|
Submitted By: PsychoCoder
|
|
|
Rating:
|
|
Views: 590 |
Language: VB.NET
|
|
Last Modified: January 1, 2008 |
Instructions: First, add the font file as a Resource, that way the font file follows the application. Second you need to add a reference to System.Drawing to gain access to the different font functionalities.
This particular snippet doesn't currently use this a as a Resource, but will be modified, improved to show how to parse a Resource File. |
Snippet
'Namespace Reference
Imports System
Imports System.Drawing
'Global variables
Private Shared PFC As Drawing.Text.PrivateFontCollection
Private Shared NewFont_FF As Drawing.FontFamily
''' <summary>
''' Function to return a new font based on the font file passed to it
''' </summary>
''' <param name="name">Path to the new font file</param>
''' <param name="style">The FontStyle of the new font</param>
''' <param name="size">T size of the new font</param>
''' <returns>A new font</returns>
''' <remarks></remarks>
Private Function CreateFont(ByVal name As String, ByVal style As Drawing.FontStyle, ByVal size As Single, ByVal unit As Drawing.GraphicsUnit) As Drawing.Font
'Create a new font collection
PFC = New Drawing.Text.PrivateFontCollection
'Add the font file to the new font
'"name" is the qualified path to your font file
PFC.AddFontFile(name)
'Retrieve your new font
NewFont_FF = PFC.Families(0)
Return New Drawing.Font(NewFont_FF, size, style, unit)
End Function
'Example Usage
Label1.Font = CreateFont("pathtofontfile",12,FontStyle.Regular,GraphicsUnit.Point)
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|