转载 C#设置控件 Enabled 为 false 时背景色不改变

class CtrEnabled
{
    [System.Runtime.InteropServices.DllImport("user32.dll ")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
    [System.Runtime.InteropServices.DllImport("user32.dll ")]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 
    const int GWL_STYLE = -16;
    const int WS_DISABLED = 0x8000000;
 
    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));
        }
    }
 
}

转载于https://blog.csdn.net/breakbridge/article/details/103913246

转载 C#设置控件 Enabled 为 false 时背景色不改变

上一篇:jitamin windows部署 笔记


下一篇:【转】C# 利用反射根据类名创建类的实例对象