How can I put a transparent PictureBox on another PictureBox?
One transparent PictureBox works on my form but i can not put a transparent PictureBox over another PictureBox.
Here is a picture from my problem.
You need to call Control.BringToFront on the PictureBox you want to be in front (on top).
Related
I need to put a picturebox above another picture box, the picturebox on top is a png file with a transparent background but when trying to use Picturebox.BringToFront(); the picturebox below is replaced with what is in the background of the form.
I tried to get around this using picturebox.Parent = picturebox2, but I don't want the picturebox to be cut off at the edges of the other picturebox it's on top of.
Good afternoon!
I have several user controls, each one with a picture box containing an image. A user control represents the backgroud and the other two are elements that must be overlayed.
pictureBox_background.BackColor = Color.Black;
pictureBox_A.BackColor = Color.Transparent;
pictureBox_background.Controls.Add(pictureBox_A);
pictureBox_background.Controls.Add(pictureBox_B);
pictureBox_B.SendToBack();
pictureBox_A.BringToFront();
With this code I get the picturebox A is over picturebox B, but I can not make the background of the element A is the image of the picturebox B. The pictureBox A reaches the background picturebox, and it's background is the black color of the background picturebox.
That is, the transparency of picturebox_A don't shows the picturebox_B, shows the black background, without showing the image of the medium (picturebox_B).
It's a little hard to explain. I hope it was understood.
Thanks in advance!
I am making an application in C#.NET with Visual Studio 2012.
I have a picture in my background form. I have several picture boxes on it. I used .png images with transparent background but in my form it is not transparent when it comes above another image.
Set your picture box back color property to transparent.
pictureBoxTest.BackColor = Color.Transparent;
To further explain, an image with a transparent background will inherit the picture box's background color. You need to set the color to transparent as well to ensure it truly is.
I have 3 pictureBoxs each one have transparent image, like this:
To make the picture 2 and picture 3 transparent for picture 1 , I wrote this code:
pictureBox2.Parent = pictureBox1;
pictureBox3.Parent = pictureBox1;
Now, my problem: How can I make picture 2 transparent for picture 3?
There's a limit to how well this will work, you are past that limit when you start to nest images. You'll then see that a PictureBox is only transparent against its Parent, parts of the composite image where other PBs contribute pixels won't be visible. You'll see the Parent's background instead.
You'll need to switch to a single PictureBox and write code. Implement its Paint event handler and call e.Graphics.DrawImage() to draw the images. Layering is now no longer a problem, paint is always transparent against its background. Also the way that WPF implements transparency.
I can't add a PNG image that contains alpha chanel into a picturebox dynamically by code because it always replace the transparent area with the black color. Is there a way to do it?
Have you tried setting the back color of the control to transparent?