views:

103

answers:

2

I am using 32bit PNG files with transparency. I added them to an image list with properties:

ColorDepth: Depth32Bit
TransparentColor: Transparent

When I assign the image to my toolbar button, it previews in Visual Studio fine with the correct transparency. But when I run the application the transparency is all messed up with black covering the semi-transparent regions.

How do I fix this?

alt text

alt text

+1  A: 

If you add them directly to the toolbar without using an image list I think they will draw correctly.

Matt Breckon
Easy solution. I also prefer this way.
OregonGhost
Well I would prefer to use an image list to make it easy to swap the images of the toolbar buttons (like the toggle inactive button).
Jack B Nimble
I agree but I've never managed to get this to work.
Matt Breckon
In my opinion, you shouldn't change a toolbar button's text or icon at runtime. You can use a checkable button for that.
OregonGhost
How do I add them directly to the toolbar?
Jack B Nimble
I guess you are using SWF 1.1 style toolbar? I suggest using the 2.0 style ToolStrip instead. This not only adds some shine to your application, but also enables setting the images directly :)
OregonGhost
A: 

The solution apparently is to put

Application.EnableVisualStyles();

Before the start of your application. This has fixed the transparency issue.

Solution Reference

MSDN on EnableVisualStyles

Jack B Nimble
Ok, I have seen this problem occur before without that resolving it. I did wonder why your second screenshot looked so chunky!
Matt Breckon