本文共 658 字,大约阅读时间需要 2 分钟。
using System.Runtime.InteropServices; public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc); 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(button1, false); button1.ForeColor = Color.White; }
转载地址:http://rcvkz.baihongyu.com/