Germcloud
Member
- Joined
- Jun 6, 2010
- Messages
- 9
- Programming Experience
- 1-3
My program uses embed fonts, I had trouble getting it to work at first, but one way I was able to get it to work was to save the font from My.Resources.FontName into a temporary file and use the file to load a font into the program. But the problem I have is that when I load the program again and I change the fonts around, it loads the same files that were created last when the program was last run, making it were I can not change the fonts to something else.
I've tried deleting the temp files in my class in Sub Finalize(), but it keeps telling me access is denied. What do I need to do to delete these files when my program closes.
Public Class clsFont
Private pfc As New System.Drawing.Text.PrivateFontCollection
Private intIndex As Integer
Private intTotal As Integer = -1
Private intFontSize() As Integer
Private fsStyle() As Drawing.FontStyle
Public Function GetFont(ByVal FontIndex As Integer) As Font
Return New Font(pfc.Families(FontIndex), intFontSize(FontIndex), fsStyle(FontIndex))
End Function
Public Function AddFont(ByVal FontResource As Byte(), ByVal FontSize As Integer, ByVal Style As Drawing.FontStyle)
intTotal = intTotal + 1
Using fs As New System.IO.FileStream("TempFile" & intTotal.ToString, IO.FileMode.Create)
fs.Write(FontResource, 0, FontResource.Length)
End Using
ResizeArrays()
intFontSize(intTotal) = FontSize
fsStyle(intTotal) = Style
'Use the resulting File as a font
pfc.AddFontFile("TempFile" & intTotal.ToString)
Return intIndex
End Function
Private Sub ResizeArrays()
ReDim Preserve intFontSize(intTotal)
ReDim Preserve fsStyle(intTotal)
End Sub
Protected Overrides Sub Finalize()
For i As Integer = 0 To intTotal
System.IO.File.Delete("TempFile" & i.ToString)
Next
MyBase.Finalize()
End Sub
End Class
Public Class Form1
Dim MyFonts As New clsFont
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyFonts.AddFont(My.Resources.Appetite, 22, FontStyle.Regular)
MyFonts.AddFont(My.Resources.BENIGHTE, 22, FontStyle.Regular)
MyFonts.AddFont(My.Resources.atlandsketchesbb_reg, 22, FontStyle.Regular)
Label1.Font = MyFonts.GetFont(0)
Label2.Font = MyFonts.GetFont(1)
End Sub
End Class
I've tried deleting the temp files in my class in Sub Finalize(), but it keeps telling me access is denied. What do I need to do to delete these files when my program closes.
Public Class clsFont
Private pfc As New System.Drawing.Text.PrivateFontCollection
Private intIndex As Integer
Private intTotal As Integer = -1
Private intFontSize() As Integer
Private fsStyle() As Drawing.FontStyle
Public Function GetFont(ByVal FontIndex As Integer) As Font
Return New Font(pfc.Families(FontIndex), intFontSize(FontIndex), fsStyle(FontIndex))
End Function
Public Function AddFont(ByVal FontResource As Byte(), ByVal FontSize As Integer, ByVal Style As Drawing.FontStyle)
intTotal = intTotal + 1
Using fs As New System.IO.FileStream("TempFile" & intTotal.ToString, IO.FileMode.Create)
fs.Write(FontResource, 0, FontResource.Length)
End Using
ResizeArrays()
intFontSize(intTotal) = FontSize
fsStyle(intTotal) = Style
'Use the resulting File as a font
pfc.AddFontFile("TempFile" & intTotal.ToString)
Return intIndex
End Function
Private Sub ResizeArrays()
ReDim Preserve intFontSize(intTotal)
ReDim Preserve fsStyle(intTotal)
End Sub
Protected Overrides Sub Finalize()
For i As Integer = 0 To intTotal
System.IO.File.Delete("TempFile" & i.ToString)
Next
MyBase.Finalize()
End Sub
End Class
Public Class Form1
Dim MyFonts As New clsFont
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyFonts.AddFont(My.Resources.Appetite, 22, FontStyle.Regular)
MyFonts.AddFont(My.Resources.BENIGHTE, 22, FontStyle.Regular)
MyFonts.AddFont(My.Resources.atlandsketchesbb_reg, 22, FontStyle.Regular)
Label1.Font = MyFonts.GetFont(0)
Label2.Font = MyFonts.GetFont(1)
End Sub
End Class