winform中真正的透明label

winform中的透明都是假透明,只是将背景色设置为父级容器的背景色。所以从网上找到这个真正透明的label。

 

 

 1 public partial class transparentLabel : UserControl
 2     {
 3         public transparentLabel()
 4         {
 5             InitializeComponent();
 6             SetStyle(ControlStyles.SupportsTransparentBackColor
 7               | ControlStyles.UserPaint
 8               | ControlStyles.AllPaintingInWmPaint
 9               | ControlStyles.Opaque, true);
10             this.BackColor = Color.Transparent;
11         }
12         protected override CreateParams CreateParams
13         {
14             get
15             {
16                 CreateParams cp = base.CreateParams;
17                 cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT 
18                 return cp;
19             }
20 
21         }
22     }

 

posted @ 2015-05-01 11:11  zhaizhuang  阅读(1877)  评论(0编辑  收藏  举报