/*============================================================================= Project: SharpImage Module: siGdiRendererForm.cs Language: C# Author: Dan Mueller Date: $Date: 2007-09-06 06:52:16 +1000 (Thu, 06 Sep 2007) $ Revision: $Revision: 23 $ 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.Diagnostics; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SharpImage.Rendering { public partial class siGdiRendererForm : siRendererForm { public siGdiRendererForm() : base(new Panel()) { // Set form control style this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); // Call the designer code InitializeComponent(); } /// /// Force the Form to repaint. /// public override void Repaint() { // Ensure the width and height are greater than 0 if (this.ViewportSize.Width > 0 && this.ViewportSize.Height > 0) { // Create a bitmap to allow double buffer rendering Bitmap bitmapOffscreen = new Bitmap(this.ViewportSize.Width, this.ViewportSize.Height); Graphics graphicsOffscreen = Graphics.FromImage(bitmapOffscreen); graphicsOffscreen.Clear(this.BackColor); // Fire the Paint event using the offscreen bitmap this.OnPaint(new PaintEventArgs(graphicsOffscreen, this.ViewportRectangle)); // All the event handlers have had their chance to paint to the // offscreen bitmap - now draw this bitmap to the form Graphics graphicsRepaintableArea = this.RenderingControl.CreateGraphics(); graphicsRepaintableArea.DrawImage(bitmapOffscreen, 0, 0); } } } }