codythecoder
codythecoder

Reputation: 452

Transparency over multiple pictureBoxes

I have an array of picture boxes that are arranged in a square. I want to put a larger, mostly transparent picture box over the top. But when I do it covers the other picture boxes and just draws the background of the form.
Is there a way to get it to have all the other picture boxes show where it is transparent?

Upvotes: 2

Views: 907

Answers (2)

Jocelyn Marcotte
Jocelyn Marcotte

Reputation: 110

Here's a tip to get the desired result:

  1. Create multiple copies of your top image.
  2. Add each copy to the Controls of each picture box it should cover.
  3. Adjust location of each copy according to the offset of each picture box to be covered.

So you will see every copy of your big image covering each picture box as if they were a single image.

Upvotes: 0

Michael Gunter
Michael Gunter

Reputation: 12811

Transparency in WinForms isn't great. Some controls have transparency support, others don't. Some controls can be subclassed to enable this (by calling Control.SetStyle() with the SupportsTransparency flag). I believe this can be done with PictureBox.

However, transparency in all WinForms controls works by having the transparent control call its parent control to draw the background before the child control draws. This means that you cannot have two sibling controls and expect transparency on one to show through to the other. Sorry!

All that said, it would be possible to code your own workaround to support this. It would involve subclassing PictureBox and clever coding in the OnPaint override to locate sibling controls and manually trigger painting of them into in-memory bitmaps. Lots of gotchas with this approach.

Try WPF!

Upvotes: 3

Related Questions