An AutoRedraw Property

This demonstrates an autoredraw property in .NET to play around with!

using System;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

public class AutoRedrawForm : Form {

private Bitmap b;

public AutoRedrawForm() {
   b = new Bitmap(this.ClientSize.Width,this.ClientSize.Height);
   this.Resize += new EventHandler(this_Resize);
   this.Paint += new PaintEventHandler(this_Paint);

private void this_Paint(object s,PaintEventArgs e) {
   if(autoredraw) {
       Graphics g = base.CreateGraphics();

private void this_Resize(object s,EventArgs e) {
   if(this.ClientSize.Width>b.Width && this.ClientSize.Height>b.Height) {
       Bitmap c = new Bitmap(this.ClientSize.Width,this.ClientSize.Height);
       Graphics g = Graphics.FromImage(c);
       b = c;

private bool autoredraw;
public bool AutoRedraw {
   get { return autoredraw; }
   set { autoredraw = value; }

public new Graphics CreateGraphics() {
   if(autoredraw) {
       return Graphics.FromImage(b);
   return base.CreateGraphics();


You might also like...


Michael H


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson