Trouble with picturebox not being transparent over other picture box

huangapple go评论56阅读模式
英文:

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.

根据文档:如何使控件具有透明背景所述,只要设置正确的父窗体,就可以实现背景透明。

因此有两种方式:

  1. 不要将其放在另一个图片框中,直接使用窗体作为背景。直接修改窗体的背景。

  2. 将马里奥所在的图片框的父级更改为覆盖整个窗体的图片框。

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:

  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

huangapple
  • 本文由 发表于 2023年4月4日 07:30:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定