CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Posts
    38

    Picture box copy?

    I have a form with 4 picture boxes on it, all boxes are identical in size & characteristics. They are set up in a control array so I can identify them with an index (0 .. 3).

    An extra picture box is hidden and used as target for LoadPicture to get the image from a file. From here pictures are copied to one of the 4 other boxes using PaintPicture. So far so good, this works OK.

    Under certain conditions I need to copy the image from one of the four picture boxes to another one of the same group of four. I first tried to do this with a simple assignment like in picBox(target).picture = picBox(source).picture but this does not work. I then tried to use PaintPicture to do the copy but this triggers run-time error 481 "Invalid Picture".

    Any idea on how to do this properly?

    The current workaround consists in re-fetching the picture from the file and use LoadPicture and PaintPicture to do the job.

    All suggestions are welcome.
    Greets,
    N.

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: Picture box copy?

    If you use PaintPicture, you must terminate by "fixing" the Picture..

    Picture1.picture = Picture1.image

    Do not forget to set the autoredraw to true (also)

    Read the following (from VB), please :

    Image Property

    Returns a handle to a persistent graphic; the handle is provided by the Microsoft Windows operating environment.

    Syntax

    object.Image

    The object placeholder represents an object expression that evaluates to an object in the Applies To list.

    Remarks

    An object's AutoRedraw property determines whether the repainting of an object occurs with a persistent graphics or through Paint events. The Windows operating environment identifies an object's persistent graphic by assigning a handle to it; you can use the Image property to get this handle.

    An Image value exists regardless of the setting for the AutoRedraw property. If AutoRedraw is True and nothing has been drawn, the image displays only the color set by the BackColor property and the picture.

    You can assign the value of Image to the Picture property. The Image property also provides a value to pass to Windows API calls.

    The Image, DragIcon, and Picture properties are normally used when assigning values to other properties, when saving with the SavePicture statement, or when placing something on the Clipboard. You can't assign these to a temporary variable, other than the Picture data type.

    The AutoRedraw property can cause Image, which is a handle to a bitmap, to change. When AutoRedraw is True, an object's hDC property becomes a handle to a device context that contains the bitmap returned by Image.

  3. #3
    Join Date
    Mar 2005
    Posts
    38

    Re: Picture box copy?

    Yes, that's it.

    I just noticed that the Picture.Width and Picture.Height values were 0 after using the PaintPicture method when I saw your reply.

    Picture.Picture = Picture.Image did the trick.

    Thank you!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured