0

Exempleim developing a super mario game and im having trouble with the pictures boxes, the picture box with mario in it its not transparent inside the mountain or the bush. (Im using a picture box as a background)

I tried change the backColours of every picture box to transparent and still doenst work.

daniel
  • 9
  • 2

1 Answers1

1

Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.

As documented: How to: Give Your Control a Transparent Background said, as long as you set the correct parent form can achieve background transparency.

So there are two ways:

  1. Don't put it on the another picturebox, just use the form as the background. Modify the background of the form directly.

  2. Change the parent of the picturebox where mario is located to the picturebox that covers the form.

picturebox2.Parent = pictureBox1;
picturebox2.BackColor = Color.Transparent
Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21
  • As for option 2, changing the `Parent` by code requires also adjusting the location of the child since controls locations are relative to their parents. So: `pictureBox2.Location = pictureBox1.PointToClient(pictureBox2 .PointToScreen(Point.Empty));`. Also, you can add option 3 that suggests changing the pbox's designer to `ParentControlDesigner` so you don't need to write any code and do it all at design time. See the referred link above. – dr.null Apr 13 '23 at 12:54
  • 1
    yes,Thank you for your experience. – Jiale Xue - MSFT Apr 13 '23 at 12:56