在 C# 代码中设置 WPF 文本框的背景颜色 [英] Set background color of WPF Textbox in C# code
本文介绍了在 C# 代码中设置 WPF 文本框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 C# 中以编程方式更改 WPF 文本框的背景色和前景色?
How can I change the background and foreground colors of a WPF Textbox programmatically in C#?
推荐答案
textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;
WPF 前景和背景是 System.Windows.Media.Brush
类型.您可以像这样设置另一种颜色:
WPF Foreground and Background is of type System.Windows.Media.Brush
. You can set another color like this:
using System.Windows.Media;
textBox1.Background = Brushes.White;
textBox1.Background = new SolidColorBrush(Colors.White);
textBox1.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));
textBox1.Background = System.Windows.SystemColors.MenuHighlightBrush;
这篇关于在 C# 代码中设置 WPF 文本框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文