Supongo que debería funcionar para copiar los datos originales de la superficie en un mapa de bits temporal antes de dibujar el rectángulo, y luego dibujar el mapa de bits en su lugar.
actualización
Ya existe una respuesta aceptada, pero pensé que podría compartir un ejemplo de código de todos modos. Éste dibuja el rectángulo dado en rojo en el control dado, y restaura el área después de 500 ms.
public void ShowRectangleBriefly(Control ctl, Rectangle rect)
{
Image toRestore = DrawRectangle(ctl, rect);
ThreadPool.QueueUserWorkItem((WaitCallback)delegate
{
Thread.Sleep(500);
this.Invoke(new Action<Control, Rectangle, Image>(RestoreBackground), ctl, rect, toRestore);
});
}
private void RestoreBackground(Control ctl, Rectangle rect, Image image)
{
using (Graphics g = ctl.CreateGraphics())
{
g.DrawImage(image, rect.Top, rect.Left, image.Width, image.Height);
}
image.Dispose();
}
private Image DrawRectangle(Control ctl, Rectangle rect)
{
Bitmap tempBmp = new Bitmap(rect.Width + 1, rect.Height + 1);
using (Graphics g = Graphics.FromImage(tempBmp))
{
g.CopyFromScreen(ctl.PointToScreen(new Point(rect.Top, rect.Left)), new Point(0, 0), tempBmp.Size);
}
using (Graphics g = this.CreateGraphics())
{
g.DrawRectangle(Pens.Red, rect);
}
return tempBmp;
}
Tenga en cuenta que en este caso el panel de superposición interceptará los clics del mouse, por lo que debe reenviar todos los eventos relevantes al panel subyacente. –