WPF文本框在C#code设置背景​​颜色 [英] Set background color of WPF Textbox in C# code

查看:349
本文介绍了WPF文本框在C#code设置背景​​颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能改变一个WPF文本框的背景色和前景色编程在C#?

解决方案

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

WPF前景和背景的类型是 System.Windows.Media.Brush 。您可以设置另一种颜色是这样的:

  //使用System.Windows.Media;

textBox1.Background = Brushes.White;
textBox1.Background =新的SolidColorBrush(Color.White);
textBox1.Background =新的SolidColorBrush(Color.FromArgb(0xFF时,为0xFF,0,0);
textBox1.Background = System.Windows.SystemColors.MenuHighlightBrush;
 

How can I change the background and foreground colors of a WPF Textbox programatically in c#?

解决方案

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

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(Color.White);
textBox1.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0);
textBox1.Background = System.Windows.SystemColors.MenuHighlightBrush;

这篇关于WPF文本框在C#code设置背景​​颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆