Pirahnaplant
Well-known member
- Joined
- Mar 29, 2009
- Messages
- 75
- Programming Experience
- 3-5
I always get this error during the Paint event:
System.AccessViolationException was unhandled
The weird thing is that it doesn't happen the first time it goes through.
Here's the code.
Symbols is just a 2 dimensional array of characters.
Edit: I'm pretty sure it has something to do with the custom font.
System.AccessViolationException was unhandled
The weird thing is that it doesn't happen the first time it goes through.
Here's the code.
VB.NET:
Friend CustomFont As Font = GetCustomFont()
Private Function GetCustomFont() As Drawing.Font
Try
Dim PFC As Drawing.Text.PrivateFontCollection
Dim NewFont_FF As Drawing.FontFamily
'Create a new font collection
PFC = New Drawing.Text.PrivateFontCollection
'Add the font file to the new font
PFC.AddFontFile(My.Application.Info.DirectoryPath & "\CustomFont.ttf")
'Retrieve your new font
NewFont_FF = PFC.Families(0)
Return New Drawing.Font(NewFont_FF, 12, FontStyle.Regular, GraphicsUnit.Point)
Catch
Return New Drawing.Font("Courier New", 12, FontStyle.Regular, GraphicsUnit.Point)
End Try
End Function
Private Sub SymbolImg_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SymbolImg.Paint
For loops1 As Integer = 0 To 10
For loops2 As Integer = 0 To 19
e.Graphics.DrawString(Symbols(loops1, loops2), CustomFont, Brushes.Black, 20 * loops2, 20 * loops1)
Next
Next
End Sub
Symbols is just a 2 dimensional array of characters.
Edit: I'm pretty sure it has something to do with the custom font.
Last edited: