[System.Runtime.InteropServices.DllImport("user32.dll ")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
        [System.Runtime.InteropServices.DllImport("user32.dll ")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        public const int GWL_STYLE = -16;
        public 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)); }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            SetControlEnabled(this.button1, false);
            this.button1.ForeColor = Color.White;
        }

 

相关文章:

  • 2021-07-04
  • 2021-06-27
  • 2021-03-31
  • 2022-12-23
  • 2022-01-29
  • 2021-06-04
  • 2021-07-26
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
相关资源
相似解决方案