Possible Duplicate:
Transparent images with C# WinForms
I am coding an app which will have a No Border. It will also have a BackgroundImage[which would be displayed as a slideshow; changed with a timer].
Sample Image [you may need to download this to experience the transparency] :

I have tried the following two methods to accomplish this :
-
Using
WindowsFormsApplication:I used the
TransparencyKeyproperty of theFormalong with setting the sameBackgroundColour.[I usedFuchsia]. Now some of the pixels in the border had the colourFuchsia. -
Using
WindowsPresentationFoundation:I used the
AllowsTransparencyof theWindowand set theBackgroundto the Image and the image was displayed correctly with transparency. Now I have to add another image at a point [by setting the margin] which i noted before in Paint.
For Example : I had the image cropped from the original background and then i have place it in the correct place in the form by setting the margin noted before.
But this causes to set a wrong margin!Update :
In WPF, If I use the
BackgroundImagein the Grid, it solves the margin problem but the Transparency just does not work and makes the transparent regions white!
Please give some hints to get out of this problem!
It is a problem caused by the image. You can see it when you load it in, say, Paint.NET and zoom in so you can see the individual pixels. The upper left corner looks like this:
Note how the pixels on the edge are partially transparent. So if you draw this image on top of a background of, say, Fuchsia then those edge pixels are no longer gray, they blend with the background and produce a different color. Which no longer matches the TransparencyKey so the video adapter won’t filter them. You’ll see them as a fringe of various shades of magenta.
You’ll need to edit the image to give it a “hard” edge without any transparency.