程序只有这段代码。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Image = PictureBox2.Image
Dim g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawEllipse(New Pen(Color.MediumOrchid, 5), 30, 30, 30, 30)
g.Dispose()
PictureBox1.Refresh()
PictureBox2.Refresh()
End Sub
点击PictureBox1
之前是emtpty,PictureBox2
有白色图片。
点击后PictureBox1
和PictureBox2
都有椭圆。
我认为程序使用一个图像用于两个pictureBox
'es.So当我绘画时它们都被绘制。我想用ellipse设置picbox2白色图像和picbox1白色图像。任何解决方案?
答案 0 :(得分:-1)
您必须制作图像的副本,因此您将使用相同的数据,但不使用相同的对象,因此不会对原始对象进行更改。
我不是vb.net专家,但你可以试试这个:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
PictureBox1.Image = New Bitmap(PictureBox2.Image)
Dim g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawEllipse(New Pen(Color.MediumOrchid, 5), 30, 30, 30, 30)
g.Dispose()
PictureBox1.Refresh()
PictureBox2.Refresh()
End Sub