|
-
Sep 8th, 2002, 05:19 PM
#1
Thread Starter
Lively Member
Drawing Text On A Form
How do you draw text onto a form
-
Sep 8th, 2002, 10:14 PM
#2
PowerPoster
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.
-
Sep 9th, 2002, 02:39 PM
#3
Thread Starter
Lively Member
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
-
Sep 9th, 2002, 02:44 PM
#4
you can leave graphics object open in that case. Would be better since you are contantly using every couple seconds.
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
|