winform控件在Enable=false的情况下改变它的字体颜色?

编程爱好者L 2010-12-23 02:58:08
控件的enable=false的时候字体的颜色为灰色,有什么办法可以使它变为其他的颜色?
...全文
1022 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
编程爱好者L 2010-12-23
  • 打赏
  • 举报
回复
果然可以 thanks
编程爱好者L 2010-12-23
  • 打赏
  • 举报
回复
四楼的方法我拿去试试看
lovelan1748 2010-12-23
  • 打赏
  • 举报
回复
貌似不能改,可以尝试下重绘
dongjianhua520520 2010-12-23
  • 打赏
  • 举报
回复
就试过combox enable属性。设置为false的时候那个颜色改不了,郁闷。
缭绕飘渺 2010-12-23
  • 打赏
  • 举报
回复
先改颜色再改为不可用
xixihaha_2011_098 2010-12-23
  • 打赏
  • 举报
回复

[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;
}
DataBox-MDX 2010-12-23
  • 打赏
  • 举报
回复
如果事先为enable=false,那么改为true,接下来改颜色,改完有将其设计为false
wudliang 2010-12-23
  • 打赏
  • 举报
回复
重新设置它的字体颜色啊
subxli 2010-12-23
  • 打赏
  • 举报
回复
我没试过,不过应该不行吧。

110,580

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧