C # Controls Enabled Set to false does not change the background color

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));
        }
    }

}

PS: this must FTFT arranged in order, so can not TTFF, otherwise abnormal 

 

Published 31 original articles · won praise 8 · views 10000 +

Guess you like

Origin blog.csdn.net/breakbridge/article/details/103913246