您的位置:首页 > 产品设计 > UI/UE

C#控件Enable设为false和true后的字体颜色修改

2012-10-23 10:01 309 查看
[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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# user