英文:
Trouble with picturebox not being transparent over other picture box
问题
I'm developing a Super Mario game and I'm having trouble with the picture boxes. The picture box with Mario in it isn't transparent inside the mountain or the bush. (I'm using a picture box as a background)
I tried changing the backgrounds of every picture box to transparent, but it still doesn't work.
英文:
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.
答案1
得分: 1
Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
根据文档:如何使控件具有透明背景所述,只要设置正确的父窗体,就可以实现背景透明。
因此有两种方式:
-
不要将其放在另一个图片框中,直接使用窗体作为背景。直接修改窗体的背景。
-
将马里奥所在的图片框的父级更改为覆盖整个窗体的图片框。
picturebox2.Parent = pictureBox1;
picturebox2.BackColor = Color.Transparent
英文:
>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:
-
Don't put it on the another picturebox, just use the form as the background. Modify the background of the form directly.
-
Change the parent of the picturebox where mario is located to the picturebox that covers the form.
picturebox2.Parent = pictureBox1;
picturebox2.BackColor = Color.Transparent
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论