Working yesterday on my remote control application that takes screenshots from a machine running XBMC I wanted to provide a better experience for the user by providing a “loading, please wait” transparent overlay image on top of the old screenshot image until new one comes in. Swimming through a lot of either complicated (Graphics.DrawImage in onPaint) or useless suggestions, I found one close to what I had in mind but didn’t give much attention to initially - using two PictureBox controls on top of each other, one for the main image and one for the overlay.
The trick is to change the background colour for the overlay picturebox to transparent and also change its parent. On top of that, if the main PictureBox is not in the top left corner and you want the overlay image to be centered, you also need to change the location of the overlay PictureBox relative to the new parent, otherwise it keeps the originally design margins.
In my case:
The trick is to change the background colour for the overlay picturebox to transparent and also change its parent. On top of that, if the main PictureBox is not in the top left corner and you want the overlay image to be centered, you also need to change the location of the overlay PictureBox relative to the new parent, otherwise it keeps the originally design margins.
In my case:
- pictureBoxMain – displays the main image, image size mode Zoom;
- pictureBoxOverlay – displays the “wait” transparent image, same size and anchoring, image size mode Center;
private void Form1_Load(object sender, EventArgs e) { // Transparent background... pictureBoxOverlay.BackColor = Color.Transparent; // Change parent for overlay PictureBox... pictureBoxOverlay.Parent = pictureBoxMain; // Change overlay PictureBox position in new parent... pictureBoxOverlay.Location = new Point(0, 0); }