Results 1 to 4 of 4

Thread: Drawing Text On A Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    83

    Drawing Text On A Form

    How do you draw text onto a form

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    VB Code:
    1. Dim g As Graphics = me.CreateGraphics()
    2. Dim string As String = "My text"
    3. Dim font As New Font("Times New Roman", 20, FontStyle.Regular)
    4. g.DrawString(string, font, SystemBrushes.Bold, 0, 0)
    5.  
    6. 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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    83
    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

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you can leave graphics object open in that case. Would be better since you are contantly using every couple seconds.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width