vb.net GDI绘图刷新问题
用GDI函数在窗体上绘图,窗体最小化或者被覆盖等的时候图像就会被抹掉,怎么Paint事件的时候保留窗体上的图像...
用GDI函数在窗体上绘图,窗体最小化或者被覆盖等的时候图像就会被抹掉,怎么Paint事件的时候保留窗体上的图像
展开
2个回答
展开全部
绘图代码写在Paint事件中,如
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = Me.CreateGraphics
g.DrawLine(Pens.Red, 100, 100, 200, 100)
End Sub
'方法二:在 PictureBox1上显示图像----图画在Bitmap
PictureBox1.Image = Nothing
Dim wid As Integer = PictureBox1.ClientSize.Width
Dim hgt As Integer = PictureBox1.ClientSize.Height
Dim bm As New Bitmap(wid, hgt)
Dim g As Graphics = Graphics.FromImage(bm)
'画图代码
'画图代码
PictureBox1.Image = bm
PictureBox1.Refresh()
g.Dispose()
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = Me.CreateGraphics
g.DrawLine(Pens.Red, 100, 100, 200, 100)
End Sub
'方法二:在 PictureBox1上显示图像----图画在Bitmap
PictureBox1.Image = Nothing
Dim wid As Integer = PictureBox1.ClientSize.Width
Dim hgt As Integer = PictureBox1.ClientSize.Height
Dim bm As New Bitmap(wid, hgt)
Dim g As Graphics = Graphics.FromImage(bm)
'画图代码
'画图代码
PictureBox1.Image = bm
PictureBox1.Refresh()
g.Dispose()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询