tags:

views:

1934

answers:

3

I have a picture box on my form, which I add a picture to. This picture has a transparent background, but unfortunately, it seems lost in the picture box... I'm guessing that's because the picture box's background colour property is set to grey (the default). I can't see any option for "transparent" though.

Any idea how I can do it?

+2  A: 

Depending on what you are trying to accomplish there's several different ways to go about it.

Some examples are -

Make bitmap transparent

Dim bmp As Bitmap = Bitmap.FromFile("test.bmp")
bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent
PictureBox1.Image = bmp

Make the picture box transparent

PictureBox1.BackColor = Color.Transparent

If you really need a transparent image I would suggest not using the picturebox and just render a transparent bitmap directly.

this will not work if the pictureBox's panel have a background image.
serhio
+1  A: 

If you want the controls behind the PictureBox to show, ie. you want your image displayed with a transparent background, try drawing straight on the form itself.

Back in the days of VB6 we could do this by hooking onto the Form's "Redraw" event or something...

Jenko
this will work, but only if your picture does not move. otherwise you will have to do with custom invalidation and custom repainting... and this is a big ......
serhio
+1  A: 

On most controls in VB, in the Backcolor property of the object, there is an option for transparency. This works fine in VB2008, but in VB2005, you must then set it's .parent property to the object behind (well, in my experience anyways.)

Hope this helps,

Lewis

Lewis Santon
Setting the parent as the background control did the trick for me in VS2005.
o.k.w