在wpf中,如何在代码中修改Button的背景色为指定颜色?

nmjyxl 2010-09-13 10:22:40
可以用这种方式:
Button.Background = System.Windows.Media.Brushes.ForestGreen;
我希望是通过“#FF255687”这样的字符串为button定义背景色。哪位大虾帮忙解决一下?
...全文
2825 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wy619118470 2012-07-29
  • 打赏
  • 举报
回复
btTemp.Background = new SolidColorBrush(Colors.MediumSlateBlue);
hbnucszhj1 2011-11-22
  • 打赏
  • 举报
回复
Color backgroundColor = (Color)ColorConverter.ConvertFromString("#FFFFFFFF");
textbox.Background = new SolidColorBrush(backgroundColor);
chazikai24 2010-09-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 nmjyxl 的回复:]

引用 1 楼 chazikai24 的回复:
C# code
button1.BackColor = ColorTranslator.FromHtml("#FF255687");

在wpf中button没有BackColor 属性
[/Quote]

这个代码是c#的,你自己看看控件背景色怎么使用System.Drawing.Color类型
nmjyxl 2010-09-13
  • 打赏
  • 举报
回复
我自己已解决,不过感谢2楼的提醒
nmjyxl 2010-09-13
  • 打赏
  • 举报
回复
SolidColorBrush myBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x25, 0x56, 0x87));

button.Background = (System.Windows.Media.Brush)myBrush;
CsToD 2010-09-13
  • 打赏
  • 举报
回复
BrushConverter conv = new BrushConverter();
Brush bru = conv.ConvertFromInvariantString("#FF255687") as Brush;
nmjyxl 2010-09-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 baesky 的回复:]
System.Drawing.Color.FromArgb(0xFF,0x25,0x56,0x87);
[/Quote]
button.background是System.Windows.Media.Brush对象,而2楼给的是System.Drawing.Color类型的。
nmjyxl 2010-09-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chazikai24 的回复:]
C# code
button1.BackColor = ColorTranslator.FromHtml("#FF255687");
[/Quote]
在wpf中button没有BackColor 属性
Baesky 2010-09-13
  • 打赏
  • 举报
回复
System.Drawing.Color.FromArgb(0xFF,0x25,0x56,0x87);
chazikai24 2010-09-13
  • 打赏
  • 举报
回复
button1.BackColor = ColorTranslator.FromHtml("#FF255687");

110,538

社区成员

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

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

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