Update Pictures in ImageList Component

S

senfo

I'm using a ListView control to display pictures similarly to how
Windows Explorer displays pictures in "Thumbnails" view. The images are
stored in an ImageList component. I would like to provide the ability
to rotate the images and I'm having some issues.

Basically, what I've tried is:

lstViewImages.LargeImageList.Images[ItemIndex].RotateFlip(RotateFlipType.Rotate90FlipNone);
lstViewImages.Update();

And:

imageListThumbNails.Images[ItemIndex].RotateFlip(RotateFlipType.Rotate90FlipNone);
lstViewImages.Update();

Obviously, the first approach accesses the ImageList component through
the ListView control, whereas the second approach accesses the ImageList
component directly. The code should, in theory, rotate the image in the
ImageList component; however, viewing the image after calling the
RotateFlip() method displays the image in its original position.

I considered removing the original image and adding it again, but that
wasn't a viable solution because the imageListThumbNails.Images
collection does not provide an Insert() method that I could use to
specify the exact index that I wish the update image to be inserted. In
other words, I could only Add() the image to the end of the collection,
which would reorder everything.

Am I doing something wrong or is there another approach I should look into?

Thank you in advance,
 
D

Dave Sexton

Hi Sean,

The ImageList.Images collection's indexer is read/write:

Image image = imageListThumbNails.Images[ItemIndex];
image.RotateFlip(RotateFlipType.Rotate90FlipNone);

// refresh the image within the ImageList
imageListThumbNails.Images[ItemIndex] = image;

// Update only works if some region has been invalidated.
// Calling Refresh does both: invalidate and update
lstViewImages.Refresh();
 
S

senfo

Dave said:
Hi Sean,

The ImageList.Images collection's indexer is read/write:

Image image = imageListThumbNails.Images[ItemIndex];
image.RotateFlip(RotateFlipType.Rotate90FlipNone);

// refresh the image within the ImageList
imageListThumbNails.Images[ItemIndex] = image;

// Update only works if some region has been invalidated.
// Calling Refresh does both: invalidate and update
lstViewImages.Refresh();

That did the trick. I'm not sure how I missed the indexer being
read/write. Also, thank you for pointing out the Refresh() method. I
hadn't realized that.

Thank you very much,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top