[.NET] Transparent Picturebox

Started by
4 comments, last by Templarian 17 years, 9 months ago
Okay image_1 (picturebox) is over image_2 (picturebox). image_1 has a .png with a transparent middle. www.templarian.com/misc/gpwiki/box.png image_2 is a random .png image repersenting a test background. This seems so simple, but i've spend the last 4 hours trying to find it out to no avail. setstyle opaque to true seems to be blocked. Q. How do I make the image_2 seen though the middle of image_1. Thanks. Someone told me to come here after he failed to find the answer out. It seems so simple it was easy in VB6 and VB.Net is newer so its probably something dumb I overlooked.
Advertisement
Making a control transparent is really the wrong approach to doing graphics. If you are going to be doing simple graphics in .Net, Your probably going to want to look into GDI+. It will do just about any 2D you want. For a complex render engine you'll probably want something more powerfull than GDI+
Strange, I've never had a problem using transparency in .NET controls. As long as you draw the background image first, then box.png you should be fine.

Can you post the code or a screenshot of what it looks like?

"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Not to sound newbish but what do you mean draw the backgroundimage you mean set a backgroundimage... ?

BTW is it possible to create my own control that just has .image .size .location becuase that way I can make it not protected and change the background to opaque (or am i thinking of this wrong).
Here is the problem with .NET control's transparency. When windows draws a control and decides that something is transparent, it then takes the PARENT'S contents (parent is the control to which your control belongs to - like the form on which the image is on) and draws that part of it.

So, if you had two image controls, if you have transparency in them, the part that is transparent will be filled in with the parent's control - ie. the form that they are on. Even if the two images overlap, they will not display one another below because they are both the child controls of the form they are on.

... and no, there is no way around this. Use GDI+ and override the Paint event.

I hope you understand, I am not so good in explaining... :(
Yea... I understand because i already knew it. I was naming its parent ealier so i could see though it but yea logically my design has multiple images over eachother at one time.

... this is going to take a lot more code than my VB6 version took. arg.

Thanks everyone.

Just for a random question what is the dumb point of setstyle if it cant be used (it can only be used on the form itself from what i saw and thats just doesnt make sense in itself)?


'edit Okay are there control arrays in .net MS isn't very smart. Still need the above question answered.

[Edited by - Templarian on July 7, 2006 2:24:46 PM]

This topic is closed to new replies.

Advertisement