-1

I have a picturebox that gets some output on similar to this:

e = New PrintPageEventArgs(PictureBox1.CreateGraphics, New Rectangle(New Point(25, 25), New Size(New Point(825, 1075))), e.PageBounds, e.PageSettings)

'Draw box
e.Graphics.DrawRectangle(Pens.Gray, 20, 30, e.PageBounds.Width - 100, e.PageBounds.Height - 130)

DrawnImage = PictureBox1.Image

I need to update it in the Paint event:

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint

    PictureBox1.Image = DrawnImage 

End Sub

The problem is DrawnImage is NULL. How do I capture the image?

Github
  • 39
  • 6

1 Answers1

0

I needed to use a bitmap instead of creating a graphics object from the picturebox.

For a complete description, please look here: How do I repaint my picturebox when the picture disappears?

Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height)

e = New PrintPageEventArgs(Graphics.GraphicsFromImage(b), New Rectangle(New Point(25, 25), New Size(New Point(825, 1075))), e.PageBounds, e.PageSettings)

'Draw box
e.Graphics.DrawRectangle(Pens.Gray, 20, 30, e.PageBounds.Width - 100, e.PageBounds.Height - 130)

PictureBox1.Image = b
Github
  • 39
  • 6