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?
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:
- If all of your images are of the same size, set this size to your ImageList at design-time.
- 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