3

I have 3 pictureBoxs each one have transparent image, like this:

enter image description here

To make the picture 2 and picture 3 transparent for picture 1 , I wrote this code:

    pictureBox2.Parent = pictureBox1;
    pictureBox3.Parent = pictureBox1;

Now, my problem: How can I make picture 2 transparent for picture 3?

Free User
  • 211
  • 2
  • 14

1 Answers1

4

There's a limit to how well this will work, you are past that limit when you start to nest images. You'll then see that a PictureBox is only transparent against its Parent, parts of the composite image where other PBs contribute pixels won't be visible. You'll see the Parent's background instead.

You'll need to switch to a single PictureBox and write code. Implement its Paint event handler and call e.Graphics.DrawImage() to draw the images. Layering is now no longer a problem, paint is always transparent against its background. Also the way that WPF implements transparency.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536