CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2002
    Location
    Ventura, Cali
    Posts
    3

    Question GDI plus how to ?

    Ok I know how to use GDI + to put text into any control when the form loads by using this.

    Private Sub test(ByVal sender As System.Object, ByVal pe As _ System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    Dim g As Graphics = pe.Graphics
    Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
    Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
    Dim myFont As New Font("arial", 24)
    g.DrawString("text here", myFont, mybrush, 300, 260)
    End Sub

    What I don't know how to do is get this to happen on command(i.e. when I press a button)

    Any help on this matter would be greatly appritiated.

    thank you
    Thank you,
    Dave Lenwell
    Software Developer
    Unlimited Cash inc.

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim g As Graphics = Graphics.FromHwnd(PictureBox1.Handle)
    Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
    Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
    Dim myFont As New Font("arial", 24)
    g.DrawString("text here", myFont, mybrush, 10, 10)
    End Sub

  3. #3
    Join Date
    Sep 2002
    Location
    Ventura, Cali
    Posts
    3

    Ok That Worked but how do I save it

    Ok That Worked but how do I save it ?

    From my documentation It works like this...

    PictureBox1.Image.Save("c:\path\testing.png", System.Drawing.Imaging.ImageFormat.Png)

    But this returns a generic GDI + error.

    I sent it to the clip board like this ...

    Clipboard.SetDataObject(PictureBox1.Image)

    it works but none of the text that I added is showing up.
    Am I going about this wrong ...

    Can I save this as an image?
    Thank you,
    Dave Lenwell
    Software Developer
    Unlimited Cash inc.

  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    I'm not suprised the changes didn't "stick" because if the picturebox is refreshed or the paint event gets called, it's going to clear and overwrite your changes with whatever is in the paint event. You might see if you can find something equivelent to the AutoRedraw property on VB 6 and see if that helps. Don't know about saving to a file, seems like I did that before with no problems (BMP format not PNG.)

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    Just did a little reading and the docs say there is no AutoRedraw equivelent. That to persist a graphic is has to be in the Paint Event. (Note though that you should be able to use RemoveHandler and AddHandler to have different paint event methods at different places in your program...)

  6. #6
    Join Date
    Sep 2002
    Location
    Ventura, Cali
    Posts
    3

    Question Clarifacation

    What I am doing here is trying to save text to an exsisting bitmap ( I don't care what format it uses )

    I am Using GDI plus to render this text to the picturbox.

    Now... on the screen it all apears the way I want it to.

    When I use picturebox.image.save("c:\path\imagename.bmp")

    It saves the Image but the text does not apear. I think this is because there is no text on the image but floating above it on the control.

    The only way I can think to pull this off is to make a screen capture of the picturebox control.

    I just don't know how to go about doing that.

    Any ideas ?¿?

    Thanks...
    Thank you,
    Dave Lenwell
    Software Developer
    Unlimited Cash inc.

  7. #7
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

  8. #8
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    You don't really need a picturebox at all... this works...

    Dim img As Image = Image.FromFile("C:\RedneckDog.jpg")
    Dim g As Graphics = Graphics.FromImage(img)
    Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, _
    Color.Blue, Color.Black, Drawing2D.LinearGradientMode.Vertical)
    Dim myFont As New Font("arial", 24)
    g.DrawString("text here", myFont, mybrush, 10, 10)

    img.Save("C:\test1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

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

Featured