小编典典

在C#代码中设置WPF文本框的背景颜色

c#

如何在C#中以编程方式更改WPF文本框的背景和前景色?


阅读 1902

收藏
2020-05-19

共1个答案

小编典典

textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;

WPF前景和背景类型System.Windows.Media.Brush。您可以像这样设置其他颜色:

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;
2020-05-19