C# - Semi Transparent Panel

This snippet shows how to develop a custom panel which is semi transparent by overriding CreateParams and the OnPaint method of the Panel control.

xPanel

  1. using System;  
  2. using System.Drawing;  
  3. using System.Drawing.Drawing2D;  
  4. using System.Windows.Forms;  
  5.  
  6. class xPanel: Panel  
  7. {  
  8.     protected override CreateParams CreateParams  
  9.     {  
  10.          get  
  11.          {  
  12.               CreateParams cp = base.CreateParams;  
  13.               cp.ExStyle |= 0x20;  
  14.               return cp;  
  15.          }  
  16.     }  
  17.  
  18.     protected override void OnPaint(PaintEventArgs e)  
  19.     {  
  20.          e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(128, 0,0,0))this.ClientRectangle);  
  21.     }  
  22.  
  23.     protected override void OnSizeChanged(EventArgs e)  
  24.     {  
  25.          base.OnSizeChanged(e);  
  26.     }  
  27. } 

No comments:

Post a Comment