VB.net PictureBox with transparent PNG - vb.net

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?

Related

How to set panel, buttons, labels and menu strip to be transparent?

I'm trying to keep transparency of buttons and labels which are inside of a panel control.
I set the BackColor properties to Transparent, but it doesn't work.
Also I tried
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.Panel1.BackColor = Color.Transparent
but it doesn't seem to work.
The screenshot below is our design plan. We try to set an image below the panel, buttons and Menu Strip. Can you tell me please if this is possible, and if so, how to?
http://www.gomidjets.com/images/upper.png
With regards to custom designing your Form in WinForms, it isn't supported very well. Only some of the controls support transparency, and it really impacts on performance. If you are avid that it must be transparent, make sure that your Form has its TransparencyKey set to a value, and then change each of the Panels, Buttons, Labels and MenuStrips background to this color (Usually some obtuse color).
If your program is in its early stages, I strongly suggest that you give WPF some serious consideration. From the level of customization to your Form you are doing, you would be much better doing WPF. I myself have just moved over, and this is a screeny of my first project in WPF (And I've learnt this all from StackOverflow, so you should pick it up pretty fast!)
As you can see, literally everything on that form has been customised, and every single control supports full Transparency!

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?

VB.NET: label vs picturebox

What is more lightweight control, a label, or a picturebox? (label can contain image too).
I will have a form with 110 icons displayed in separate controls and I'm deciding if I should display them in pictureboxes, or a labels.
In VB6, there was an Imagebox control which was MUCH more lightweight than picturebox. What is the most similar control to Imagebox in VB.NET?
Thanks! :-)
Although I know it's not part of your question, the real problem it seems you are experiencing is the fact that you have 110 icons in a single form. I would take a look at the UI and see if there is a better way to lay it out or design it so you don't have to worry about whether or not to use one component vs the other.
I don't think you can compare them because fundamentally they are so different--VB6 controls versus .net framework controls that is.
Take a look at the class hierarchy in .net and you will see that both picturebox and label derive from the same set of classes.
While I didn't itemize the classes' properties and methods, I would guess that the only difference between a Label and a Picturebox is that there is a text property for a Label box thus alleviating you of rendering your own text if there were no Label control and all you had was a PictureBox.
Both a Label and a PictureBox can be assigned an Image object or work in conjunction with an ImageList. So if all you are looking to do is display images then the PictureBox should be just fine (not to mention the fact that it clearly conveys the control's purpose in life: PictureBox:Icons::Label:Text).

Transparency for images in Visual Basic .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)