Results 1 to 3 of 3

Thread: How To Copy A PictureBox Drawing From One PictureBox To Another???????????

Hybrid View

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    1

    Exclamation How To Copy A PictureBox Drawing From One PictureBox To Another???????????

    Hello,

    I have a program in which you can create comic strips. When you first see the comic it is a plain comic with loads of picturebox's that are being used as the panels for it. Now, when you click on a panel an external editor opens with a picturebox that allows you to draw your own comic strip and then save it to the first picturebox.

    My problem is: When i try to copy the picturebox with the drawing image on to the first picturebox, it does nothing.

    How can i Do this correctly?

    Need me to explain more on how it works?

    Dear god help?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: How To Copy A PictureBox Drawing From One PictureBox To Another???????????

    Call the Clone() method of the Image class. For example:
    Code:
    PicuterBox2.Image = PictureBox1.Image.Clone()
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Frenzied Member boops boops's Avatar
    Join Date
    Nov 08
    Location
    Holland/France
    Posts
    1,974

    Re: How To Copy A PictureBox Drawing From One PictureBox To Another???????????

    Hi Steadi,
    welcome to VBForums. This sounds like the kind of program I like. There are two main alternatives if you are hand-drawing on a picture box. You can do it directly using Graphics methods in the Paint sub of the picture box. Or you could do the drawing on a bitmap, and then show the bitmap in the picture box (either set the PictureBox.Image to equal the bitmap, or draw the bitmap in the Paint event with Graphics.DrawImage). Personally I would prefer the second method for this application. Drawing on a bitmap gives a cleaner design because you can always resize the bitmap, to copy it to another picture box, to save it to a file etc. instead of making those operations dependent on the state of the picture box.

    On the other hand, if you are drawing directly in the picture box's Paint sub, it's not hard to take a snapshot of the picturebox with the DrawToBitmap method. It copies exactly what the picture box shows, pixel for pixel. Here's an example of how to use it:

    Code:
    Dim rect As Rectangle = PictureBox1.ClientRectangle
    Dim bmp As New Bitmap(rect.Width, rect.Height)
    PictureBox1.DrawToBitmap(bmp, rect)
    PictureBox2.Image = bmp
    Note the use of ClientRectangle. It excludes the picturebox border (if any) so it is more accurate than using the Width and Height properties.

    By the way, if you do want to copy an existing image I recommend doing it like this:
    Code:
    PictureBox2.Image = New Bitmap(PictureBox1.Image)
    Stanav's Clone method will work if you have Option Strict Off, but it's not ideal because the output of the Clone method of Object type rather than Image.

    BB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •