Transparency for images in Visual Basic .net? - vb.net

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?

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.

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...

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,

I know this is an old topic, but I figured I'd post the solution I came up with for anyone looking for a simple solution for Windows Forms. Say you have PictureBox1 and PictureBox2. You want PictureBox2 to overlay on PictureBox1. Make sure your PictureBox1 background is set to transparent. Then, you can programmatically set:
PictureBox2.Parent = PictureBox1
Magic

Transparent an Image, You can also used Adobe Photoshop to Remove White/Black Background (Watch Tutorial How to Create Transparent Background)
or Use this code below,
PictureBox1.BackColor = Color.Transparent
SetStyle(ControlStyles.SupportsTransparentBackColor, True)

Related

Transparent PNG over labels and textboxes on my .Net form

I have a project where I want to place a png on the form like a "Rubber Stamp". I have the transparent *.png but I need it to be transparent on TOP of all the textboxes, labels, etc. Every time that I use a label or picturebox to hold the image, you still see the form background. It's not being brought transparent on top.
Any assistance is appreciated.
Assuming I understood your question right, let's say you have a PictureBox called PictureBox1, and a Label called Label1, and you've placed PictureBox1 in front of Label1, and the PictureBox has a transparent background. In the form's load event:
PictureBox1.Parent = Label1
If this doesn't work, try adding
PictureBox1.BringToFront()

VB.net PictureBox with transparent PNG

I hope someone can help me.
I have placed a few PictureBoxes in a VB.net app in Visual Studio 2012 (Express). I've set the Picturebox BackColor to Transparent and used a PNG with alpha-transparency in the PictureBox.
My intention is to slightly overlap a few of the PictureBoxes. The problem is the PictureBoxes dont appear to be acknowledging the transparency. When the BackColor is set to transparent, it appears as if the BackColor is automatically set to that of the Form, and not to be truly transparent.
As such, when I overlap the PictureBox, the one at the top (furthest forward) doesnt let the parts of the one below it "peek through" at the transparency.
Am I doing something wrong? I even tried using a GIF image (although this wouldnt be ideal due to lack of alpha-channel support), but this did the same thing. I find it odd that this doesnt work properly when I could do this back in the VB6 days (albeit with GIF only and not PNGs), so i must be doing something wrong.
Please could someone help?

Picture Box and Form Transparency

Maybe I am missing something, but is it the case that when you set a pictureboxes background to transparent, all it really does is set it to the same color as the forms background?
What I am trying to do is draw an animation for the benefit of this, a bouncing ball - which I paint on the form, then overlay that with a picture frame. End result should be a bouncing ball in a picture frame, I should mention that the picture frame does not have a straight edge, so it is not possible to arrange 4 picture boxes in a frame. The ball needs to vanish behind the frame to change color and then magically bounce back out.
I have tried:
1.Setting the picture box background to pink and then key out the same pink, this basically cuts away everything, including that which is behind the picture box
2.Setting the picture box to transparent, this just displays the picture box background as the same color as the forms background.
3.I have tried painting the image in a rectangle, this had the same effect as drawing it in a picture box.
I am not sure what I am doing wrong, I am wondering if there is any other ways I could try or if someone has made a custom control or library that supports transparency?
Try using a Panel with the background image set. This is because; as you said: the transparent option only takes the backcolour of the parent.
After doing some more in depth research I solved this by drawing both the images to the form using PaintEventArgs and me.paint
Making each image transparent using:
Dim TestImage as Bitmap
TestImage.MakeTransparent(<Transparency Color>)
Thank you to both of you for your replies though.
Hmm... If You want to use Picturebox and get a transparent image,
Try to set picturebox's background as your 'Ball' (probably you need an image editor).
and set picturebox transparent. It worked for me (VS Express 2010) once.

VB.net transparent png overlaying each other.. getting Form Background color

Trying to start a game that involve in a lot of .png and animation.
All these .png are already transparent and set to an individual picture box when i overlay one over the other. There "transparency" actually gets the form background color. and not i'm not able to see through the image behind it.
i set the forecolor to transparent in the attribute am i missing something?
*side question... should i make my game in vb.net if it using a lot of images and animations files? (working solo might get my friend to help later)
Example pictures
well, this is a bit old, but check my answer here :
Make Picturebox transparent over other picturebox?

Panel containing PictureBox flickers on background change. How can I eliminate this?

I have a panel with the BackgroundImage set that I'm using as a button. The panel also contains a PictureBox with a png image loaded so that parts of the image are transparent and the panel image shows through. On MouseDown I change the panels BackgroundImage, then on MouseUp I change it back again. The problem is that when the panel image changes, the PictureBox flickers badly when redrawing its transparent areas.
I've tried using the DoubleBuffered property of the form its on; no luck there. I've also tried SuspendLayout just before changing the image, refreshing the PictureBox, then ResumeLayout. Still no luck.
Thanks in advance for any ideas.
It's the bad part of VS in graphic. Try using Form BackgroundImage property, or overrides OnPaint event and use Graphics class to draw the image manually (draw on the Form).