[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 980
  • 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.

Thanks,

Steve
0
wsprhino
Asked:
wsprhino
1 Solution
 
Fernando SotoCommented:
Try settiong the TransparencyKey property of the Form to the color Color.Cyan
0
 
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.

Steve
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

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