<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>DoubleBufferedPanel</Title>
      <Shortcut>DoubleBufferedPanel</Shortcut>
      <Description>DoubleBufferedPanel [C#]</Description>
      <Author>david huntley</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=ae53e89e-6562-49b8-8cc7-e25e5300cffa</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace GeminiCricket
{
    class DoubleBufferedPanel : Panel
    {
        public DoubleBufferedPanel()
        {
            this.DoubleBuffered = true;
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true);
            this.UpdateStyles();
        }
        protected override void OnScroll(ScrollEventArgs se)
        {
            if (se.Type == ScrollEventType.First) LockWindowUpdate(this.Handle);
            else if (se.Type == ScrollEventType.ThumbTrack || se.Type == ScrollEventType.ThumbPosition)
            {
                LockWindowUpdate(IntPtr.Zero);
                this.Refresh();
                LockWindowUpdate(this.Handle);
            }
            else
            {
                LockWindowUpdate(IntPtr.Zero);
                this.Invalidate();
            }
            base.OnScroll(se);
        }
        // P/Invoke declarations
        [DllImport("user32.dll")]
        private static extern bool LockWindowUpdate(IntPtr hWnd);
    }
}]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>