title: Drawing a TextBox in an extended Glass Frame w/o WPF
body: <p>I am trying to draw a TextBox on the extended glass frame of my form. I won't describe this technique, it's well-known. Here's an example for those who haven't heard of it: <a href="http://www.danielmoth.com/Blog/Vista-Glass-In-C.aspx" rel="nofollow noreferrer">http://www.danielmoth.com/Blog/Vista-Glass-In-C.aspx</a></p>
  
  <p>The thing is, it is complex to draw over this glass frame. Since black is considered to be the 0-alpha color, anything black disappears.</p>
  
  <p>There are apparently ways of countering this problem: drawing complex GDI+ shapes are not affected by this alpha-ness. For example, this code can be used to draw a Label on glass (note: <code>GraphicsPath</code> is used instead of <code>DrawString</code> in order to get around the horrible ClearType problem):</p>
  
  <pre><code>public class GlassLabel : Control
  {
      public GlassLabel()
      {
          this.BackColor = Color.Black;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          GraphicsPath font = new GraphicsPath();
  
          font.AddString(
              this.Text,
              this.Font.FontFamily,
              (int)this.Font.Style,
              this.Font.Size,
              Point.Empty,
              StringFormat.GenericDefault);
  
          e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
          e.Graphics.FillPath(new SolidBrush(this.ForeColor), font);
      }
  }
  </code></pre>
  
  <p>Similarly, such an approach can be used to create a container on the glass area. Note the use of the polygons instead of the rectangle - when using the rectangle, its black parts are considered as alpha. </p>
  
  <pre><code>public class GlassPanel : Panel
  {
      public GlassPanel()
      {
          this.BackColor = Color.Black;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          Point[] area = new Point[]
              {
                  new Point(0, 1),
                  new Point(1, 0),
                  new Point(this.Width - 2, 0),
                  new Point(this.Width - 1, 1),
                  new Point(this.Width -1, this.Height - 2),
                  new Point(this.Width -2, this.Height-1),
                  new Point(1, this.Height -1),
                  new Point(0, this.Height - 2)
              };
  
          Point[] inArea = new Point[]
              {
                  new Point(1, 1),
                  new Point(this.Width - 1, 1),
                  new Point(this.Width - 1, this.Height - 1),
                  new Point(this.Width - 1, this.Height - 1),
                  new Point(1, this.Height - 1)
              };
  
          e.Graphics.FillPolygon(new SolidBrush(Color.FromArgb(240, 240, 240)), inArea);
          e.Graphics.DrawPolygon(new Pen(Color.FromArgb(55, 0, 0, 0)), area);
  
          base.OnPaint(e);
      }
  }
  </code></pre>
  
  <p>Now my problem is: How can I draw a TextBox?
  After lots of Googling, I came up with the following solutions:</p>
  
  <ul>
  <li>Subclassing the TextBox's <code>OnPaint</code> method. This is <em>possible</em>, although I could not get it to work properly. It should involve painting some magic things I don't know how to do yet.</li>
  <li>Making my own custom <code>TextBox</code>, perhaps on a <code>TextBoxBase</code>. If anyone has <em>good</em>, valid and working examples, and thinks this could be a good overall solution, please tell me.</li>
  <li>Using <code>BufferedPaintSetAlpha</code>. (<a href="http://msdn.microsoft.com/en-us/library/ms649805.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms649805.aspx</a>). The downsides of this method may be that the corners of the textbox might look odd, but I can live with that. If anyone knows how to implement that method properly from a Graphics object, please tell me. I personally don't, but this seems the best solution so far. To be honest, I found a great C++ article, but I am way too lazy to convert it. <a href="http://weblogs.asp.net/kennykerr/archive/2007/01/23/controls-and-the-desktop-window-manager.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/kennykerr/archive/2007/01/23/controls-and-the-desktop-window-manager.aspx</a></li>
  </ul>
  
  <p>Note: If I ever succeed with the BufferedPaint methods, I swear to s/o that I will make a simple DLL with all the common Windows Forms controls drawable on glass.</p>