0

I have a background image, then I want to load several others on top of this. Each image is a png with an alpha channel that has different areas non-transparent.

I placed a PicureBox on a form. Then in the code:

private List<PictureBox> layers = new List<PictureBox>();

for (int l = 0; l < 11; l++)
{
    Image i = (Image) Properties.Resources.ResourceManager.GetObject(l.ToString());
    PictureBox b = new PictureBox
    {
        Parent = form_picture,
        Image = i,
        Dock = DockStyle.Fill,
        SizeMode = PictureBoxSizeMode.Zoom,
        BackColor = Color.Transparent
    };
    //b.BringToFront();

    layers.Add(b);
}

where "form_picture" is the PictureBox placed on the form, and my resource images are named 0,1,2..10.

It shows only the first image or the last one (removing the comment to the BringToFront method). It doesn't seem a problem of transparency because I correctly see the background image, but only the first or last opaque area of the upper levels.

I'm afraid I'm not using correctly the properties.

A R
  • 1,412
  • 2
  • 14
  • 29
Mark
  • 4,338
  • 7
  • 58
  • 120
  • Yes. In fact if I reparenting each other (i.e. 0 to background, 1 to 0, 2 to 1, etc...) I see all opaque areas (as expected) and the background picture on transparent areas. But I cannot hide just one now (it will hide all the children too) – Mark Oct 14 '17 at 12:03
  • @someone: https://stackoverflow.com/questions/19910172/how-to-make-picturebox-transparent – Mark Oct 14 '17 at 12:04

1 Answers1

1

IMO, you shouldn't use pictureboxes at all. They're too expensive for what You're trying to do. Use Graphics.DrawImage instead.
The System.Drawing.Image has a PixelFormat property of type System.Drawing.Imaging.PixelFormat that should help you with the alpha channel.

Behrooz
  • 1,696
  • 2
  • 32
  • 54
  • Well, there are only 10 PictureBox, I don't think this is too expensive. It just doesn't work (this is why I don't like .NET). Solved manually drawing images in the OnPaint event... – Mark Oct 14 '17 at 12:36