title: How to stop the flickering of Panels containing multiple controls
body: <p>I have some questions regarding flickering and the general flow of UI updates
  when multiple objects are involved.</p>
  
  <p>Background: 
  We use a C# assembly inside a Progress ABL application to drive the UI.
  Additionally we use Infragistics controls, as they can easily be styled.
  We have a kind of self made MDI. (tab) panels contain multiple user controls which
  are used as "Forms".
  (Note: Real forms could not be used, because a non-toplevel form has problems handling mouse clicks correctly)
  The tabs are realized by an Infragistics UltraDockManager.</p>
  
  <p>On such an UserControl "form" a Progress .Net Control is placed which embeds real Progress Frames.
  So we could re-use existing Progress Forms instead of rebuilding them in .NET from scratch.
  To make things worse we use a tiled backgroundimage on the (tab) panels.</p>
  
  <p>Now we have the problem that the contents of the panel (derived from Infragistics.Win.Misc.UltraPanel)
  are flickering heavily. (Especially when the main application is resized)
  Some controls (especially the Progress controls) are deleted and redrawn.</p>
  
  <p>I could get rid of the flickering by using WS_CLIPCHILDREN and WS_EX_COMPOSITED
  (as mentioned by Hans Passant in <a href="https://stackoverflow.com/questions/2612487/how-to-fix-the-flickering-in-user-controls">How to fix the flickering in User controls</a> ) in the panel and the UserControl.
  But the application was noticeably slower than before, so I had to removed the code again.</p>
  
  <p>I tried setting the Styles of the panel and the UserControl, with absolutely no effect.</p>
  
  <pre><code>this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.ResizeRedraw, true);
  </code></pre>
  
  <p>Trying to ignore WM_ERASEBKGND in the panel and the UserControl seems not to have an effect either.</p>
  
  <pre><code>protected override void WndProc(ref Message m)
  {
      if (m.Msg != WM_ERASEBKGND)
      {
          base.WndProc(ref m);
      }
  }
  </code></pre>
  
  <p>What would be the correct way to handle the redrawing of all those objects to reduce the flickering?</p>
  
  <p>I thought about using SendMessage and WM_SETREDRAW. But I am not sure where to put it
  in this scenario and whether it would really help or not.</p>
  
  <p>When the application is resized each UserControl seems to be repainted, regardless of its visibility. (Could be scrolled half way out of view)
  Why isn't there some kind of clipping going on? The panel should know that some areas don't need to be refreshed or am I mistaken?</p>
  
  <p>I would appreciate any suggestion.</p>