png image and transparency

  • Thread starter Thread starter Martijn Mulder
  • Start date Start date
M

Martijn Mulder

When I populate a ToolStrip with ToolStripButtons with a .png-image on
it, will Windows understand the transparency of the .png file?
 
When I populate a ToolStrip with ToolStripButtons with a .png-image on
it, will Windows understand the transparency of the .png file?


Most Windows.Forms classes allow you to choose a color to consider
transparent. Usually this property is called TransparentColor.
Usually, I choose Color.Magenta (r=255,g=0,b=255). Just use this color
for all pixels that need to be transparent. The advantage is that it's
pretty easy to set up with basic image manipulation tools.

Cheers
Bram
 
Martijn said:
When I populate a ToolStrip with ToolStripButtons with a .png-image on
it, will Windows understand the transparency of the .png file?

Yes and no. Actually, I haven't tried this with a ToolStrip in
particular, but this did come up recently with other Control-based classes.

The transparency of the PNG is in fact preserved. However, the Control
background itself is still erased before the PNG with transparency is
drawn. This may apply to the ToolStripItem-derived classes too.

In this case, choosing "transparent" as the background color for the
item causes the background to be erased using the parent's color.
Assuming there's no overlap in your controls, this will have the net
effect of making the transparency in the image appear to work correctly.
But if there's overlap, you get that erased background on top of
whatever the underlying control is.

I don't actually know whether the ToolStripItem-derived classes have the
same behavior, but it seems possible that they would. Your best bet, of
course, is to try it. Then post back here with the answer. :)

Pete
 
Peter Duniho schreef:
Yes and no. Actually, I haven't tried this with a ToolStrip in
particular, but this did come up recently with other Control-based classes.

The transparency of the PNG is in fact preserved. However, the Control
background itself is still erased before the PNG with transparency is
drawn. This may apply to the ToolStripItem-derived classes too.

In this case, choosing "transparent" as the background color for the
item causes the background to be erased using the parent's color.
Assuming there's no overlap in your controls, this will have the net
effect of making the transparency in the image appear to work correctly.
But if there's overlap, you get that erased background on top of
whatever the underlying control is.

I don't actually know whether the ToolStripItem-derived classes have the
same behavior, but it seems possible that they would. Your best bet, of
course, is to try it. Then post back here with the answer. :)

Pete


It works fine with my application. Only thing is that it seems 'to easy'
since I have gone through a lot of trouble defining a Region-object to
restrict the drawing to just the portion I want. And suddenly there is a
lot easier way with .png and transparency. C# is just to versatile
 
Back
Top