lable picturebox等控件背景颜色透明

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

例: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;

你可能感兴趣的:(winform,控件,WinForm,Enabled重写)