Transparent Key problem

vincentchang

Newcomer
Joined
Oct 7, 2005
Messages
6
Dear all,

I have a problem when dealing with transparent key of main form and controls on the form.

I set an background image for a form and then set the TransparencyKey of the form to Color.Red so that the red region on the background image becomes transparent. I placed picturebox on the form and the picturebox is used to display image selected by user. I found that the red region in the image of the picturebox becomes transparent as well but what I want to do is only make the red region of the main form to be transparent and picturebox remains unchanged so that the picture will be displayed correctly.

Could anyone suggest how to make controls on the form remain unchanged when transparentkey of the form is set.

Thank you very much in advance! :)

Vincent
 
Why don't you use a more obscure color as your TransparencyKey? Like... R = 253, G=0, B=1
The TransparencyKey is a formwide graphical thing. Therefore, you tend to have to make your transparency key almost intentionally weird... so that other pictures that possess a color that looks like this one will not fall through the TransparencyKey.

P.S. Most applications like this have a color scheme, and the transparency key would probably be a color that is not in the color scheme.
 
A very common transparency key is Magenta (R=255, G=0, B=255). This is not a particularly unusual color, but it is ugly and useless so it is used very often as a trasnparency key and it is the color of my preference. But any color will do as long as you can ensure that only the areas to be rendered as transparent will be this color.

If you are allowing a user to load custom images into a picturebox it is hard to guaruntee that your transparent color won't be loaded and displayed incorrectly. In this case you might want to investigate other methods of non-rectangular controls. You can do this without going through the Windows API. Try creating a System.Drawing.Region and setting it to the System.Windows.Forms.Form.Region property.
 
Back
Top