title: Control flickers while drawing in .Net Compact Framework
body: <p>I have a control which draws some items on a bitmap.</p>
  
  <p>I am using the Microsoft gesture library to scroll and pan the bitmap.</p>
  
  <p>While doing panning or scrolling my bitmap flickers a lot.</p>
  
  <p>I am drawing just a portion of bitmap in <code>OnPaint</code> method depending on scroll/panned cordinates.</p>
  
  <p>Following is the sample code:</p>
  
  <pre><code>protected override void OnPaint(PaintEventArgs e)
          {
              using (Graphics g = e.Graphics)
              {
                  if (!_painted)
                  {
                      // drawing items first time
                      InitilizeBitmap(g);                 
                      _painted = true;
                  }           
  
                  Rectangle rec = new Rectangle(0, _bitmapLocation.Y, ClientRectangle.Width, ClientRectangle.Height);
                  using (Graphics gCached = Graphics.FromImage(_cachedBitmap))
                  {
                      gCached.Clear(BackColor);
                      gCached.DrawImage(_bmpControl, 0, 0, rec, GraphicsUnit.Pixel);
                  }
  
                  g.DrawImage(_cachedBitmap, 0, 0);
              }
          }
  
          protected override void OnPaintBackground(PaintEventArgs e)
          {
  
          }
  </code></pre>
  
  <p>Is there a way to avoid flickering ?</p>