I have 2 PictureBox elements in my WinForms app. I want the gray PictureBox to display an image, and the one above it will be used as some kind of a canvas for drawing a rectangle. But I can't get the PictureBox to be transparent, all the time, when I launch the app it displays the color, white (or the one you see the picture box in), I have set the BackColor of that PictureBox to Transparent, but it still doesn't work.
CodePudding user response:
It is quite easy all you have to do is make the canvas PictureBox of the same size and set its location also the same as your first picture box. Then set canvas PictureBox back colour to transparent. Now set your first PictureBox as the parent of canvas PictureBox.
You can write the below code on the form load event.
pictureBoxCanvas.Size = pictureBox1.Size;
pictureBoxCanvas.Location = pictureBox1.Location;
pictureBoxCanvas.BackColor = Color.Transparent;
pictureBoxCanvas.BringToFront();
pictureBoxCanvas.Parent = this.pictureBox1;