Question Transparent Picturebox

gididaf

Member
Joined
Dec 30, 2010
Messages
8
Programming Experience
5-10
Hi everyone!
my problem is simple
i'm using VB 2010 and i'm trying to make a transparent images but without success
i draw 2 GIF pictures in Photoshop and save it as transparent
i put that GIF's in 2 pictureboxes on the form

and the background of the pictures is really transparent, but when i try to put one picture in the top of the other one, the first picture cover the second one with the background color (and becuase it's transparent it's like the form color)

you can see a simple print screen that explain the problem:
http://img535.imageshack.us/img535/2476/94862168.png

i search all the web and didn't find anything usefull...

thanks alot :)
 
That is because, in WinForms, a transparent control is not really transparent. A transparent control basically creates a copy of the area of its parent that it covers and then displays that as its background. When you have two overlapping PictureBoxes, the parent of the top one is the form, not the bottom PictureBox, so you can see through the top PictureBox to the form, but not the bottom PictureBox.

What you need to do is not use multiple PictureBoxes. You might use one or none at all. Either way, you would use GDI+ to draw the Images onto either the form itself or onto the same PictureBox.

I'd suggest using one PictureBox. Make it big enough to cover the area required for both Images. Handle the Paint event of the control and call e.Graphics.DrawImage twice, drawing the bottom Image first and then the top one.
 
That is because, in WinForms, a transparent control is not really transparent. A transparent control basically creates a copy of the area of its parent that it covers and then displays that as its background. When you have two overlapping PictureBoxes, the parent of the top one is the form, not the bottom PictureBox, so you can see through the top PictureBox to the form, but not the bottom PictureBox.

What you need to do is not use multiple PictureBoxes. You might use one or none at all. Either way, you would use GDI+ to draw the Images onto either the form itself or onto the same PictureBox.

I'd suggest using one PictureBox. Make it big enough to cover the area required for both Images. Handle the Paint event of the control and call e.Graphics.DrawImage twice, drawing the bottom Image first and then the top one.

WOW! Thanks! i own you my life :)
now i can build a cool game!! thankssssssssssssss
 
Back
Top