How do you draw text onto a form
Printable View
How do you draw text onto a form
VB Code:
Dim g As Graphics = me.CreateGraphics() Dim string As String = "My text" Dim font As New Font("Times New Roman", 20, FontStyle.Regular) g.DrawString(string, font, SystemBrushes.Bold, 0, 0) g.Dispose()
I got that out of a book, should work though. The basic concept is to get the forms graphics object. Once you have that, you can draw whatever you want to it. A little warning the book throws out about the graphics object, which I haven't tested yet, is that you should dispose of the graphics object as soon as your done with it because it takes a lot of memory. You can let the garbage collector get to it also by letting it fall out of scope, but the quicker it gets scheduled for disposal the better.
If im gonna be drawing stuff once every 3 seconds then should I just create the object at the beginning and leave it to be disposed when the user quits the program or should I keep creating and disposing it every 3 secs.
Oh and the code works well except I put Dim drawBrush As New SolidBrush(Color.Black) and put drawBrush in instead of SystemBrushes.Bold
you can leave graphics object open in that case. Would be better since you are contantly using every couple seconds.