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;
}
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#控件Enable设为false和true后的字体颜色修改
- c# 如何调整 Button 控件在 Enable = false 时的字体颜色
- 【转】C# 实现完整功能的截图控件(2)-实现颜色和字体选择控件
- C# WinForm窗体控件Panel修改边框颜色以及边框宽度方法
- 如何修改几种控件的颜色和字体
- 【android开发】 修改控件Spinner内容的字体大小 颜色等属性
- 关于MFC中修改控件字体和背景颜色的方法
- Dialog中屏蔽“Esc”热键 & 修改控件字体或背景颜色
- 修改树控件特定节点上的字体和颜色
- 如何修改几种控件的颜色和字体
- C# 中代码Dialog控件实现(打开,保存,改变字体,颜色,打印功能)
- C# WinForm窗体控件GroupBox修改边框颜色控件
- 修改控件Spinner内容的字体大小 颜色等属性
- Android NumberPicker控件修改分割线颜色及字体颜色大小
- 修改控件Spinner内容的字体大小 颜色等属性
- Win32设置修改STATIC控件字体、颜色
- 如何修改几种控件的颜色和字体
- 如何修改几种控件的颜色和字体[转]
- WTL环境中CEdit或Cstatic控件中修改字体大小和颜色
- C#中修改提示字体及颜色