38

I am making an application in C# .NET. I have 8 picture boxes in it. I used PNG images with transparent background but in my form it is not transparent when it comes above another image.

I am using Visual Studio 2012. This is a screenshot of my form:

How to make picturebox transparent? (1)

c# winforms picturebox

edited Apr 18, 2016 at 15:31

Termininja

6,16712 gold badges45 silver badges48 bronze badges

asked Nov 11, 2013 at 15:39

Belal KhanBelal Khan

1,8842 gold badges20 silver badges30 bronze badges

4

74

One way to do this is by changing the parent of the overlapping picture box to the PictureBox over which it is lapping. Since the Visual Studio designer doesn't allow you to add a PictureBox to a PictureBox, this will have to be done in your code (Form1.cs) and within the Intializing function:

public Form1(){ InitializeComponent(); pictureBox7.Controls.Add(pictureBox8); pictureBox8.Location = new Point(0, 0); pictureBox8.BackColor = Color.Transparent;}

Just change the picture box names to what ever you need. This should return:

How to make picturebox transparent? (4)

edited Dec 18, 2015 at 18:50

Erik Humphrey

3433 silver badges17 bronze badges

3

Video: C# WinForms Tutorial 1 [PART1]- Blending background PictureBox to front transparent PictureBox

6

GameBoard is control of type DataGridView;The image should be type of PNG with transparent alpha channel background;

Video: Visual Basic 2010 Express Tutorial 31 - Picture Transparency - PNG Images Within PictureBoxes

 Image test = Properties.Resources.checker_black; PictureBox b = new PictureBox(); b.Parent = GameBoard; b.Image = test; b.Width = test.Width*2; b.Height = test.Height*2; b.Location = new Point(0, 90); b.BackColor = Color.Transparent; b.BringToFront();

How to make picturebox transparent? (7)

answered Jun 8, 2016 at 16:39

Stav BodikStav Bodik

1,7902 gold badges16 silver badges22 bronze badges

1

Try using an ImageList

ImageList imgList = new ImageList;imgList.TransparentColor = Color.White;

Load the image like this:

picturebox.Image = imgList.Images[img_index];

answered Nov 11, 2013 at 15:56

tttonytttony

4,1114 gold badges24 silver badges37 bronze badges

I've had a similar problem like this.You can not make Transparent picturebox easily such as picture that shown at top of this page, because .NET Framework and VS .NET objects are created by INHERITANCE! (Use Parent Property).

I solved this problem by RectangleShape and with the below code I removed background,if difference between PictureBox and RectangleShape is not important and doesn't matter, you can use RectangleShape easily.

private void CreateBox(int X, int Y, int ObjectType){ ShapeContainer canvas = new ShapeContainer(); RectangleShape box = new RectangleShape(); box.Parent = canvas; box.Size = new System.Drawing.Size(100, 90); box.Location = new System.Drawing.Point(X, Y); box.Name = "Box" + ObjectType.ToString(); box.BackColor = Color.Transparent; box.BorderColor = Color.Transparent; box.BackgroundImage = img.Images[ObjectType];// Load from imageBox Or any resource box.BackgroundImageLayout = ImageLayout.Stretch; box.BorderWidth = 0; canvas.Controls.Add(box); // For feature use }

answered Feb 9, 2014 at 16:23

Hamed MirzaeiHamed Mirzaei

618 bronze badges

Video: How to make picturebox transparent - C#

1

One fast solution is set image property for image1 and set backgroundimage property to imag2, the only inconvenience is that you have the two images inside the picture box, but you can change background properties to tile, streched, etc. Make sure that backcolor be transparent.Hope this helps

answered Sep 18, 2014 at 10:18

i31nGoi31nGo

Video: Create Transparent Image in C#

1,24614 silver badges10 bronze badges

Just use the Form Paint method and draw every Picturebox on it, it allows transparency :

 private void frmGame_Paint(object sender, PaintEventArgs e) { DoubleBuffered = true; for (int i = 0; i < Controls.Count; i++) if (Controls[i].GetType() == typeof(PictureBox)) { var p = Controls[i] as PictureBox; p.Visible = false; e.Graphics.DrawImage(p.Image, p.Left, p.Top, p.Width, p.Height); } }

answered Jan 29, 2021 at 14:20

rouliozroulioz

9

-2

you can set the PictureBox BackColor proprty to Transparent

answered Nov 11, 2013 at 15:45

1

Video: VB2010 Express Tutorial 31 Picture Transparency PNG Images Within PictureBoxes

Not the answer you're looking for? Browse other questions tagged c# winforms picturebox or ask your own question.