0

I want to move labels with images above other labels with images and dont want the ugly black background. So i tried to use this:

Bitmap alienbild = new Bitmap(@"path.png");
public Form1()
{
Color backColour = alienbild.GetPixel(0, 0);
alienbild.MakeTransparent(backColour);
labelalien.Size = new Size(50, 35);
labelalien.Image = alienbild;
}

The picture I am using is also 50x35 and drawn in Paint, if that matters. The background colour of the label is also set to transparent.

But the background is still black, ruining my beautiful pictures drawn in paint. With a mouse.

What do I miss?

Thank you in advance!

Cadaris
  • 9
  • 1
  • You sample only 1 pixel but most likely not all 'background' pixels actually have this exact color. Also make sure the Label is nested not overlapping other controls as transparency in winforms is only supported for nested, not for overlaping controls!! – TaW Jun 22 '17 at 07:55
  • If everything is transparent then you get to see the back of the monitor. *Somebody* has to decide what the background should look like. Label can [properly show](https://stackoverflow.com/a/9387562/17034) the foreground of its Parent as its background, but stacking effects don't work. Stacking layers of paint on top of each other requires a different rendering technique, the one that WPF uses by default. In Winforms you'd use the Graphics class, not the Control class. Label and PictureBox are very wasteful alternatives to Graphics.DrawString() and Graphics.DrawImage(). But convenient. – Hans Passant Jun 22 '17 at 08:06
  • All the background pixels have the same exact colour, i checked. What do you mean with nested? I want to move a label with the .Image property and a transparent background above another label with an Image that is not transparent. – Cadaris Jun 23 '17 at 08:06
  • Found a similar question with a solution here: https://stackoverflow.com/a/3794318/8122668 – Firzanah Sep 25 '17 at 09:16

0 Answers0