private void Form1_Paint(object sender, PaintEventArgs e) { SolidBrush brush = new SolidBrush(Color.Gray); if (memGraphics.CanDoubleBuffer()) { // Fill in Background (for effieciency only the area that has been clipped) memGraphics.g.FillRectangle(new SolidBrush(SystemColors.Window), e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); // Do our drawing using memGraphics.g instead e.Graphics memGraphics.g.FillRectangle(brush, this.ClientRectangle); if (myPane != null) { myPane.Draw(memGraphics.g); } // Render to the form memGraphics.Render(e.Graphics); } else // if double buffer is not available, do without it { e.Graphics.FillRectangle(brush, this.ClientRectangle); if (myPane != null) { myPane.Draw(e.Graphics); } } }
/// <summary> /// Render content to a bitmap. /// </summary> protected override void Render(Bitmap bitmap, Rectangle renderRect) { using (var graphics = Graphics.FromImage(bitmap)) { graphics.SetClip(renderRect); _graphPane.ReSize(graphics, new RectangleF(0, 0, bitmap.Width, bitmap.Height)); _graphPane.Draw(graphics); } }