Monday, January 31, 2011

PictureBox with transparent overlay picture (C#)

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:
  • 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);
}


Wednesday, January 19, 2011

Troubleshooting Nonpaged and Paged Pool Errors in Windows (Ben Lye)

http://www.simple-talk.com/content/article.aspx?article=970

Ben Lye uncovered a memory leak in the nonpaged pool which was crashing his servers with disquieting regularity. Luckily it was relatively easy to troubleshoot, and he's sharing the tools and techniques he used to get his servers back on track in double-quick time.

Having troubles with one of our development servers (non paged pool, event ID 2019) I found this blog post very easy to follow. Also a must read is Mark Russinovich's Pushing the Limits of Windows: Paged and Nonpaged Pool blog post going into some more detail.