tags:

views:

98

answers:

2

I'm using standard BMP images for buttons that come with visual studio. When using these images within a resource (resx) file, how do I set the transparency key?

This has always worked fine for me using an ImageList, but I want to reuse the images among many dialogs within the same assembly which I would also like the ability to control the images through resource bundles allowing for image localization.

Some of the images I'm talking about can be found in:

%VS_PATH%\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary\VS2008ImageLibrary\Annotations&Buttons\bmp_format

A: 

Although I wanted to do it through the designer I think this is the only way I can figure out how to achieve what I'm after.

Bitmap bmp = new Bitmap(MyAppResources.MyImageResource);
bmp.MakeTransparent(Color.Fuchsia);
Button btn = new Button();
btn.Image = bmp;
Brett Ryan
+2  A: 

You can do it through the designer. Add an ImageList to your form and set its TransparentColor property. Add the image. Set the button's ImageList and ImageIndex properties.

Hans Passant
Thanks nobugs, as mentioned that's how I have always done it, however if I have multiple forms/user-controls that I wish to share the same resources against them I can't. I wanted to have different images for different locales which is why I wanted to use a resource bundle. I can always inherit from ImageList and build the list which will be accessible through the designer, however an image-list loads all resources when the form is opened which if that form only concerned itself with one image resource it would be loading more than it needed.
Brett Ryan
ImageList.Images is a localized property as well. You don't have to load it with all resources.
Hans Passant
Thanks, I didn't' realise that `ImageList.Images` was localizable, that's great and I'll do that, but what it does mean is that the whole ImageList needs to be loaded when accessed even if all images aren't being used. Now one could suppose that many image lists could be created to minimise redundant loading.
Brett Ryan
Just readdressing this, how do you get ImageList.Images to be localizable? The image list will become localized for that dialog only which is not sharable between other dialogs that use the same images.
Brett Ryan