网上扒的非常好用 直接CV大法就可以用
[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)); }
}
SetControlEnabled(this.button1, false);//我的是button控件 你可以随意
如果想要修改字体颜色
this.button4.ForeColor = ColorTranslator.FromHtml(color);