lable picturebox等控件背景颜色透明

来源:互联网 发布:淘宝最新photoshop 编辑:程序博客网 时间:2024/05/17 00:55

这里的透明是用 控件的背景颜色与上层的背景色一致产生类似透明效果。

例:this.lable1.BackColor = Color.Transparent;


当设置控件为Disable(Enabled=false)时。上面的方法就不行了,这时要重写Enabled方法

 public static void SetControlEnabled(Control c, bool enabled)        {            if (enabled)            { SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); }            else            { SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(c.Handle, GWL_STYLE)); }        }

调用

SetControlEnabled(this.lable1, false);

 this.lable1.BackColor = Color.Transparent;