|
-
May 3rd, 2013, 07:15 AM
#1
[RESOLVED] Changing Fonts at Runtime.
Hi, I'd like an opinion on the following code...
vb.net Code:
Private Sub Face(ByVal a As Integer)
'Style 0 regular, 1 Bold, 2 Italic, 3 Bold Italic.
If a = 1 Or a = 2 Then
Label2.Font = GFR(My.Resources.MTCORSVA, 48, 2)
Label3.Font = GFR(My.Resources.MTCORSVA, 34, 2)
Label4.Font = GFR(My.Resources.MTCORSVA, 34, 2)
Else
Label2.Font = GFR(My.Resources.albanyzc, 36, 3)
Label3.Font = GFR(My.Resources.albanyc, 28, 0)
Label4.Font = GFR(My.Resources.albanyc, 28, 0)
End If
End Sub 'Set Type face.
Private Function GFR(ByVal FontResource As Byte(), _
ByVal Size As Integer, _
ByVal Style As FontStyle) As Drawing.Font
Dim Fc As New Drawing.Text.PrivateFontCollection
Fc.AddMemoryFont(Runtime.InteropServices.Marshal. _
UnsafeAddrOfPinnedArrayElement(FontResource, 0), _
FontResource.Length)
Return New Drawing.Font(Fc.Families(0), Size, Style)
End Function 'Get Font from Resource
The font files are in Resources, and also in C:\Windows\Fonts.
I've been using this code for a couple of years or so, but every now and then something in the project causes the Labels to malfunction, in that they're just the outline of where they should be with no text, and crossed out in red, two red lines from opposite corners, corner to corner. (That's to the best of my memory, it doesn't happen all that often and my memory isn't what it once was).
Strangely, if I run the project again, even immediately after closing it when it malfunctioned, it'll display correctly. This problem occurs fairly often on my wife's laptop but quite rarely on my PC. This project is called from the Start Menu so all sorts of other things are likely to be happening at the same time, so I'm trying to eliminate this part of the equation.
Poppa.
Along with the sunshine there has to be a little rain sometime.
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
|