如何在最小化后的图片框上绘制而不丢失内容,vb.net

  • 本文关键字:net vb 绘制 最小化 vb.net drawing
  • 更新时间 :
  • 英文 :


当我最小化表单时,我会丢失图片框上绘制的所有内容。我想把它保留在图片盒上。请在这方面帮助我。代码如下所示。。

Private Sub ButtonDraw_Click(sender As Object, e As EventArgs) Handles ButtonDraw.Click
Dim g As Graphics = PictureBox1.CreateGraphics
Dim MyPen As New Pen(Color.Red)
MyPen.Width = 2
MyPen.DashStyle = DashStyle.Solid
g.TranslateTransform(PictureBox1.Width / 2, PictureBox1.Height / 2)
g.DrawEllipse(MyPen, New Rectangle(-150, -150, 300, 300))
End Sub

示例代码,在Paint()事件中使用e.Graphics,如Jimi:所建议

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim g As Graphics = e.Graphics
Using MyPen As New Pen(Color.Red)
MyPen.Width = 2
MyPen.DashStyle = DashStyle.Solid
g.TranslateTransform(PictureBox1.Width / 2, PictureBox1.Height / 2)
g.DrawEllipse(MyPen, New Rectangle(-150, -150, 300, 300))
End Using
End Sub

最新更新