Arkadaşlar merhaba, Aşağıda ki code'u çalıştıramadım bir türlü. İşin ilginç tarafı DrawString'e debug line koyunca çalışması run time debug yapmadığım zaman çalışmaması. Olay ilgiç olduğu için youtube olarak özetledim. Eğer fırsat bulup bir incelerseniz memnun olacağım. Hatanın kaynağının ne olduğunu bulamadım belki siz yardım edersiniz
Public Class Form1
Dim uc As New ClassA
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
uc.DrawString("Hello World1")
uc.DrawString("Hello World2")
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Controls.Add(uc)
uc.DrawString("Here")
End Sub
End Class
Class ClassA
Inherits UserControl
Dim bm As System.Drawing.Bitmap
Dim gr As System.Drawing.Graphics
Dim picheight As Integer = 0
Dim picwidth As Integer = 0
Dim myFont As New Font("Arial", 8)
Dim gOffset As Integer = 0
Sub New()
MyBase.Width = 200
MyBase.Height = 200
picwidth = MyBase.Width
picheight = MyBase.Height
bm = New System.Drawing.Bitmap(picwidth, picheight)
gr = System.Drawing.Graphics.FromImage(bm)
gr.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
AddHandler MyBase.Paint, AddressOf DrawArea
End Sub
Public Function DrawString(pText As String) As Long
gr.DrawString(pText, myFont, Brushes.Black, New Point(0, gOffset))
gOffset = gOffset + myFont.GetHeight
MyBase.Update()
End Function
Public Sub DrawArea(sender As Object, e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(bm, New Point(0, 0))
End Sub
End Class