• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 987
  • Last Modified:

Can I set a transparent color for an image?

I have an image which I use on a toolstrip button which has cyan set as the transparency color. When I display the image on the button I can get it to display the image without the cyan pixels - so it draws a circle without the background for example.

When I create a label on a form and set the same image to be displayed without any text there appears to be no way to stop it from displaying the cyan background to the circle. The properties available for label are not the same set of properties for a toolstrip button.

Is there some way I can display the circle on the form without the cyan background?  I could choose to set the background to be the background color for the form but this has two problems. 1. I then need to maintain two images(one for the toolstrip button and one for the form). 2. If I change the background color of the form dynamically I can't change the background color of the circle to match.


1 Solution
Fernando SotoRetiredCommented:
Try settiong the TransparencyKey property of the Form to the color Color.Cyan
wsprhinoAuthor Commented:

Setting the TransparencyKey just means that the background of the image is displayed as the color of the form that underlies the form on which the control lies.

Also, I have a case in which the image is placed on a control which in turn is placed on a form and the control does not have TransparencyKey property.

I could read the resource bitmap and convert all the cyan pixels to the current background color of the form. But, this seems like a sledgehammer approach. I have tried using controls other than labels but they all have the same problem. Buttons, picture boxes both have the same problem. It is a pity MS cannot provide a consistent interface where we have the same control over label images as we do with toolstrip button images. It also means that I need to regenerate the bitmap each time the forms background color is changed.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now