如何更改TextBox的背景颜色? [英] How to change TextBox's Background color?

查看:80
本文介绍了如何更改TextBox的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的C#代码如下:

I got C# code that is like:

if(smth == "Open")
{
    TextBox.Background = ???
}    

如何更改TextBox的背景颜色?

How to change TextBox's background color?

推荐答案

如果是WPF,则静态类 Brushes 中有一组颜色.

If it's WPF, there is a collection of colors in the static class Brushes.

TextBox.Background = Brushes.Red;

当然,您可以根据需要创建自己的画笔.

Of course, you can create your own brush if you want.

LinearGradientBrush myBrush = new LinearGradientBrush();
myBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
myBrush.GradientStops.Add(new GradientStop(Colors.Orange, 0.5));
myBrush.GradientStops.Add(new GradientStop(Colors.Red, 1.0));
TextBox.Background = myBrush;

这篇关于如何更改TextBox的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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