绘图事件绘制两个对象

绘图事件绘制两个对象

本文介绍了绘图事件绘制两个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 白色的图像。



c> PictureBox2 都有椭圆。



我认为程序使用两个 pictureBox 'es。所以当我画他们都画。我想设置picbox2白色图像和picbox1白色图像椭圆。任何解决方案?

解决方案

您必须复制图像,因此您将使用相同的数据,但不使用相同的对象,对象。



我不是vb.net专家,但您可以试试这个:

  Private Sub Button1_Click(sender As Object,e As EventArgs)处理
Button 1.单击
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


Program has only this code.

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

Before clicking PictureBox1 is emtpty and PictureBox2has a white image.

After clicked PictureBox1 and PictureBox2 both have ellipse.

I think program uses one image for two pictureBox'es.So when I paint they are both painted.I want to set picbox2 white image and picbox1 white image with ellipse.Any solution ?

解决方案

You have to make a copy of the image, so you will use the same data, but not the same object, and so are safe from changes on the original object.

I am not a vb.net expert, but you may try this:

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

这篇关于绘图事件绘制两个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:06