Is it possible to have two overlapping PictureBox controls with transparent images? [duplicate]

你。 提交于 2019-12-03 05:18:35

Try this

private void Form1_Load(object sender, EventArgs e)
{
  // Transparent background...  
  pictureBoxOverlay.BackColor = Color.Transparent;

  // Change parent for overlay PictureBox...
  pictureBoxOverlay.Parent    = pictureBoxMain;

 // Change overlay PictureBox position in new parent...
 // pictureBoxOverlay.Location  = new Point(0, 0);
}

Result

llink

As far as I know, the transparency of a control depends on its parent control (As noted in the link you've given), meaning that in order to have the effect you are looking for, you need to have one picture box nested into another picture box which is impossible given that a picture box is not a container.

You can however, use a custom container control instead of a picture box for the parent image. The most basic control would be a panel. Just set the background image of the control and put the second picture box in it.

Another solution, would be to use one single picture box and manage the rendering manually.

This is by far the best solution as the pseudo-simulated transparency of the other method is quiet inefficient.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!