/*=============================================================================
Project: SharpImage
Module: siRepaintablePanel.cs
Language: C#
Author: Dan Mueller
Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $
Revision: $Revision: 2 $
Copyright (c) Queensland University of Technology (QUT) 2007.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=============================================================================*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace SharpImage.Rendering
{
class siRepaintablePanel : Panel
{
///
/// Default constructor.
///
public siRepaintablePanel() : base()
{
}
///
/// Force the panel to paint to an offscreen bitmap before drawing this bitmap to the actual control.
///
public void Repaint()
{
// Create a bitmap to allow double buffer rendering
Bitmap imgOffscreen = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, PixelFormat.Format32bppArgb);
Graphics gOffscreen = Graphics.FromImage(imgOffscreen);
gOffscreen.Clear(this.BackColor);
// Fire the Paint event using the offscreen bitmap
this.OnPaint(new PaintEventArgs(gOffscreen, this.ClientRectangle));
// All the panel event handlers have had their chance to paint to the
// offscreen bitmap, now draw the bitmap to the control
Graphics gPanel = this.CreateGraphics();
gPanel.DrawImage(imgOffscreen, 0, 0);
}
}
}