title: Drawing on top of controls inside a panel (C# WinForms)
body: <p>I know this question had been asked more than a few times, but so far I haven't been able to find a good solution for it.</p>
  
  <p>I've got a panel with other control on it.<br>
  I want to draw a line on it and on top of all the controls in the panel</p>
  
  <p>I came across 3 types of solutions (non of them worked the way I wanted) :</p>
  
  <ol>
  <li><p>Get the desktop DC and Draw on the screen.<br>
  This will draw on other applications if they overlap the form.</p></li>
  <li><p>Overriding the panel's "CreateParams":</p></li>
  </ol>
  
  <p>=</p>
  
  <pre><code>protected override CreateParams CreateParams {  
    get {  
      CreateParams cp;  
      cp = base.CreateParams;  
      cp.Style &amp;= ~0x04000000; //WS_CLIPSIBLINGS
      cp.Style &amp;= ~0x02000000; //WS_CLIPCHILDREN
      return cp;  
    }  
  }           
  </code></pre>
  
  <p>//NOTE I've also tried disabling WS_CLIPSIBLINGS</p>
  
  <p>and then drawing the line OnPaint().
  But... Since the panel's OnPaint is called before the OnPaint of the controls in it, 
  the drawing of the controls inside simply paints on top of the line.<br>
  I've seen someone suggest using a message filter to listen to WM_PAINT mesages, and use a timer, but I don't think this solution is either "good practice" or effective.<br>
  What would you do ?  Decide that the controls inside have finished drawing after X ms, and set the timer to X ms ?</p>
  
  <hr>
  
  <p>This screen shot shows the panel with WS_CLIPSIBLINGS and WS_CLIPCHILDREN turned off.<br>
  The Blue line is painted at the Panel's OnPaint, and simply being painted on by the textboxes and label.<br>
  The Red line is painted on top only because it's not being painted from the panel's OnPaint (It's actually painted as a result of a Button being clicked)<br>
  <img src="https://i73.photobucket.com/albums/i201/sdjc1/temp/screen3.png" alt="alt text"></p>
  
  <hr>
  
  <p>3rd: Creating a transparent layer and drawing on top of that layer.<br>
  I've created a transparent control using:</p>
  
  <pre><code>protected override CreateParams CreateParams {  
    get {  
      CreateParams cp = base.CreateParams;  
      cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT  
      return cp;  
    }  
  }
  </code></pre>
  
  <p>The problem is still, putting the transparent control on top of the Panel and all its controls.<br>
  I've tried bringing it to the front using: "BringToFront()" , but it didn't seem to help.<br>
  I've put it in the Line control's OnPaint() handler.<br>
  Should I try putting it somewhere else ??<br>
  - This also creates issue with having another control on top of the panel. (catching the mouse clicks etc..)  </p>
  
  <p><strong>Any help would be greatly appreciated!</strong></p>
  
  <p>**EDIT:
  The black line is a sample of what I was trying to do. (used windows paint to paint it)</p>
  
  <p><img src="https://i73.photobucket.com/albums/i201/sdjc1/temp/screen2.jpg" alt="alt text"></p>