Results 1 to 4 of 4

Thread: Trouble with Graphics.drawstring

  1. #1

    Thread Starter
    Hyperactive Member DerekM's Avatar
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    296

    Trouble with Graphics.drawstring

    Having some trouble, need help.
    So, what I've got is a picturebox and a textbox, I got some code to put text into a picturebox so I could better understand how it works, but what I don't understand is how to put the text on top of the image that is in the picturebox, can anyone tell me how to do that?

    Here's the code

    vb Code:
    1. Dim Graph As Graphics
    2. Dim Drawbitmap As Bitmap
    3. Dim Brush As New Drawing.SolidBrush(Color.Black)
    4. private sub textbox1_text changed( byval sender as blah blah blah...)
    5. Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
    6. Graph = Graphics.FromImage(Drawbitmap)
    7. PictureBox1.Image = Drawbitmap
    8. Graph.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    9. Graph.DrawString(TextBox1.Text, TextBox1.Font, Brush, PictureBox1.Location)
    10. end sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Trouble with Graphics.drawstring

    If you want the text on the Image that's in the PictureBox then you have to create your Graphics object from the Image that's in the PictureBox, not from some new Image that you just created. If you want to write on a book then you write on that book. You don't go and get a new book and write on that. The same goes here. These two lines are the issue:
    Code:
    Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
    Graph = Graphics.FromImage(Drawbitmap)
    If you want to draw on an existing Image then don't create a new Image.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member DerekM's Avatar
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    296

    Re: Trouble with Graphics.drawstring

    So then how do I fix it?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Trouble with Graphics.drawstring

    How do you normally access the Image in the PictureBox? How do you display an Image in the PictureBox in the first place?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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