|
-
April 19th, 2006, 08:24 AM
#1
Transparent Picture box in Windows Form?
How do I create a transparent PictureBox in a Windows Form? I tried setting the BackColor to Transparent, but that wasn't valid and didn't work.
-
April 19th, 2006, 08:38 AM
#2
Re: Transparent Picture box in Windows Form?
If u want fully-transparent just turn the visibility property 2 false
-
April 19th, 2006, 08:44 AM
#3
Re: Transparent Picture box in Windows Form?
i suggest you use a panel loaded with a background picture instead - picturebox cant receive some events either (DragDrop )
-
April 19th, 2006, 08:48 AM
#4
Re: Transparent Picture box in Windows Form?
I'm not sure that it's possible, some controls in .NET do not behave as expected.
You can always try using a Panel instead. Either set its BackgroundImage property, or subscribe to the Paint event and display your image.
[Edit. cjard beat me to it]
Useful? Then click on (Rate This Post) at the top of this post.
-
April 19th, 2006, 10:06 AM
#5
Re: Transparent Picture box in Windows Form?
So there's no way at all to do this? I changed the image to a Panel and drew it in OnPaint...but the blank spots are still being filled in with some color instead of showing what's behind the image. It would seem like this is common enough that there would be some way to do it.
-
April 19th, 2006, 10:19 AM
#6
Re: Transparent Picture box in Windows Form?
Did you set the BackColor to Transparent?
Useful? Then click on (Rate This Post) at the top of this post.
-
April 19th, 2006, 01:31 PM
#7
Re: Transparent Picture box in Windows Form?
Yep...still draws yellow'ish pixels instead of transparent (i.e. whatever color the object behind them is) ones.
-
April 19th, 2006, 01:49 PM
#8
Re: Transparent Picture box in Windows Form?
Instead of setting the BackColor of the picturebox to Transparent, try changing the bitmap itself.
Code:
Bitmap pic = new Bitmap(pictureBox1.Image);
for (int x=0; x<pic.Width; x++)
for (int y=0; y<pic.Height; y++)
{
Color pixel = pic.GetPixel(x,y);
if (pixel == someColor) //You might need to compare RGB
pic.SetPixel(x,y,Color.Transparent);
}
pictureBox1.Image = pic;
Put the code in the ImageChanged event of the PictureBox. It will work if you are not changing the picture all the time.
-
April 20th, 2006, 01:30 AM
#9
Re: Transparent Picture box in Windows Form?
Here is an article on transparency in Windows Forms: http://www.bobpowell.net/transcontrols.htm. I wouldn't recommend the solution he provides but at least it outlines the general limitations.
Useful? Then click on (Rate This Post) at the top of this post.
-
April 20th, 2006, 10:25 AM
#10
Re: Transparent Picture box in Windows Form?
 Originally Posted by jhammer
Instead of setting the BackColor of the picturebox to Transparent, try changing the bitmap itself.
Thanks!
I have a map of strings->Images that I load at startup. This map contains all the files that will be in the picturebox. Also, they're all the same shape, so this really makes the most sense as I know exactly what pixels need to be set to Transparent. Works great!
-
April 20th, 2006, 12:36 PM
#11
Re: Transparent Picture box in Windows Form?
maybe i misunderstood your question.. i thought you were talking about a transparent PictureBox, but i now realise you are talking about loading a picture that contains transparent pixels, into a picturebox and they arent rendered as transparent.. ?
-
April 21st, 2006, 02:40 AM
#12
Re: Transparent Picture box in Windows Form?
 Originally Posted by cjard
maybe i misunderstood your question.. i thought you were talking about a transparent PictureBox
 Originally Posted by LooselyBased
How do I create a transparent PictureBox in a Windows Form?
That may have been the problem! 
Congratulations must go to jhammer for working out the real problem.
Useful? Then click on (Rate This Post) at the top of this post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|