c# overlay an image on top of another

后端 未结 1 1929
陌清茗
陌清茗 2021-01-24 04:27

i am currently trying to put the notes on top of the staff image. However, the notes background are being set to the form background as shown in the image. image type used is p

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 04:38

    You are not really overlaying images. You are overlaying controls with images.

    For this to work with transparency, your notes controls need to be nested in the staff control!

    As they aren't, the transparency shows the color of their actualy parent, i.e. the form.

    Set p.Parent=panel4 and adapt the locations accordingly, i.e. make them relative to the staff..

    This is a limitation of winforms transparency, which doesn't support overlapping controls. Nested controls will work fine but only by faking the transparent parts by copying them from the parent..

    Note that as a consequence you will not be able to have the notes overlap each other or be overlapped by any other controls.

    Often giving up on using controls is the better way; instead one can simply draw all parts that make up the total..

    So you could do a series of e.Graphics.DrawImage(noteImg, x, y) in the panel4_Paint event.

    0 讨论(0)
提交回复
热议问题