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

相关文章:

  • 2021-04-02
  • 2021-11-21
  • 2021-04-22
  • 2021-07-28
  • 2021-08-31
  • 2021-10-11
  • 2021-11-12
  • 2021-08-11
猜你喜欢
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-18
相关资源
相似解决方案