Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

Don't Flicker! Double Buffer!

Rate me:
Please Sign up or sign in to vote.
4.83/5 (57 votes)
31 Jan 2006CPOL4 min read 424K   13.4K   210  
Demonstrates several ways to overcome the annoying flickering problem
In this article, you will see how double buffering is a good and simple to use technique that helps overcome the flickering problem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DoubleBufferExample
{
	public partial class Example : Form
	{
		public Example()
		{
			InitializeComponent();

            PaintMethodSelector.SelectedIndex = 0;
            TestMethodSelector.SelectedIndex = 0;
		}
        private void RefreshTimer_Tick(object sender, EventArgs e)
        {
            DoubleBufferControl1.Invalidate();
        }

		private void PaintMethodSelector_SelectedIndexChanged(object sender, EventArgs e)
		{
			DoubleBufferControl1.PaintMethod = 
				(DoubleBufferControl.DoubleBufferMethod) PaintMethodSelector.SelectedIndex;
		}

        private void TestMethodSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            DoubleBufferControl1.GraphicTest =
                (DoubleBufferControl.GraphicTestMethods)TestMethodSelector.SelectedIndex;
        }

		private void RefreshInterval_ValueChanged(object sender, EventArgs e)
		{
			RefreshTimer.Interval = (int) RefreshInterval.Value;
		}

        private void StartBtn_Click(object sender, EventArgs e)
        {
            RefreshTimer.Enabled = true;
        }

        private void StopBtn_Click(object sender, EventArgs e)
        {
            RefreshTimer.Enabled = false;
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions