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 }
时间: 2024-10-09 17:52:18