title: Creating semi-transparent panels/controls. Is there a foolproof way?
body: <p>I am trying to create a semi-transparent control derived from <code>System.Windows.Forms.Panel</code>. [Edit: Basically what I want to achieve is this]:</p>
  
  <p><img src="https://i.stack.imgur.com/irXrP.png" alt="enter image description here"></p>
  
  <p>I have gone through numerous web articles as well as SO questions and have come up with this:</p>
  
  <pre><code>class SeeThroughPanel : Panel
  {
      public SeeThroughPanel()
      {
      }
  
      protected override CreateParams CreateParams {
          get {
              var cp = base.CreateParams;
              cp.ExStyle |= 0x00000020;
              return cp;
          }
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          //base.OnPaint(e);
          e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 0, 0, 0)), this.ClientRectangle);
      }
  }
  </code></pre>
  
  <p>Which results this (Note that this code too does not make it really semi-transparent. The button is displayed in full color, unlike in above image):</p>
  
  <p><img src="https://i.stack.imgur.com/hvjUV.png" alt="Custom control shows transparency as expected."></p>
  
  <p>However, as soon as I do something that causes repaint of any other controls within the bounds of the semi-transparent panel, it is overdrawn (In this case, I have scrolled the underlying control):</p>
  
  <p><img src="https://i.stack.imgur.com/MwJ1X.png" alt="Custom control incorrectly repainted."></p>
  
  <p>So my question is, how can I avoid this? There <em>has</em> to be some way. After all, web browsers handle this kind of rendering all the time.</p>