首页 > 解决方案 > 如何使用绘制的内容重新绘制图片框?

问题描述

我有一个图片框,可以得到类似这样的一些输出:

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

我需要在 Paint 事件中更新它:

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

    PictureBox1.Image = DrawnImage 

End Sub

问题是 DrawnImage 为 NULL。如何捕捉图像?

标签: .net

解决方案


我需要使用位图而不是从图片框创建图形对象。

完整的描述请看这里:图片消失时如何重新绘制图片框?

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

推荐阅读