views:

22

answers:

1

I am using an imagelist with a label control, basically doing custom rolleover affect. However, if I use an imagelist and try and write the image to the label it keeps shrinking the image to 16x16, even when the image in the list is actually 21 high by 65 wide, why is this and how can I stop it, basically display image at its default size?

+1  A: 

The problem comes from the ImageList. It has a property ImageSize that has a big impact on the List itself.

If you take a look at design time into the images of your ImageList, they will all show up their real width and height values. But by compile time the images will be stored within the list using the given ImageSize. So all images within a ImageList will be already stretched to the given size at runtime.

Attention: If you change the ImageSize at runtime all images will be removed from the list!

To solve your problem you have two possibilities:

  1. If all of your images are of the same size, set this size to your ImageList at design-time.
  2. If you have images of different sizes you should add them to your Resources.resx file and access them from there, cause here they will be saved as is and access is also fairly easy like Properties.Resources.MyPictureFile
Oliver
Thanks Oliver, I didn't notice that the imagelist had a restriction like that, another odd ms choice I feel, but yes I did go with the resx file in the end and access them that way. Turned out nice in the end :) Thanks.
flavour404