4

I want to make a PictureBox semi transparent: show the conent of a picturebox on the back put not the base color of the form.

My Project

enter image description here

The little PictureBoxs that are on the front shows the back color of the form (control) (it have "Transparent" as background color), but I want to show color Red (the background image of the big PictureBox). How can I do it?

Hunter Turner
  • 6,592
  • 11
  • 37
  • 55
hos130
  • 53
  • 3
  • Tough ask with WinForms, not kidding, I'm serious... – Fᴀʀʜᴀɴ Aɴᴀᴍ Mar 04 '16 at 18:40
  • Look at [this](http://stackoverflow.com/questions/4144371/a-picturebox-problem) and [this](http://stackoverflow.com/questions/19747926/override-a-transparent-picturebox-in-c-sharp-windows-application-form). – Fᴀʀʜᴀɴ Aɴᴀᴍ Mar 04 '16 at 18:42
  • 2
    You see the Parent in the background. Usually the form, never another PictureBox unless you assign the Parent property in code. Check the PictureContainer class in [this post](http://stackoverflow.com/a/9387562/17034). – Hans Passant Mar 04 '16 at 18:42
  • 1
    No tranparency in winforms unless with __nested__ controls. To nest inside a PB you need to code it, as Hans said..: `picBoxSmall1.Parent = picBoxbig; picBoxSamll.Location = ....` – TaW Mar 04 '16 at 18:48
  • Is the red box a Picturebox? – Kyle Williamson Mar 04 '16 at 19:30
  • the red box is a PictureBox with a bagkground image. – hos130 Mar 05 '16 at 20:08

1 Answers1

1

This may not exactly answer you question, if it is not helpful, I can delete my answer. I am not sure if I completely understood. If your background image is going to be a simple PictureBox with a single color, the following should code work.

pictureBox1 - an image of a simple star

enter image description here

pictureBox2 - my red background image

Bitmap b = new Bitmap("Star.png");
b.MakeTransparent(Color.White);
pictureBox1.Image = b;
pictureBox1.BackColor = pictureBox2.BackColor; 

Before:

enter image description here

After:

enter image description here

Kyle Williamson
  • 2,079
  • 4
  • 39
  • 69
  • This code works if the background image is not a simple color? for example a map of some world region – hos130 Mar 05 '16 at 20:07