如何更改TextBox的背景颜色?

Sub*_*oFX 10 .net c# wpf

我得到的C#代码如下:

if(smth == "Open")
{
    TextBox.Background = ???
}    
Run Code Online (Sandbox Code Playgroud)

如何更改TextBox的背景颜色?

Mar*_*ila 19

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

TextBox.Background = Brushes.Red;
Run Code Online (Sandbox Code Playgroud)

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

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;
Run Code Online (Sandbox Code Playgroud)


Dim*_*rov 17

在WinForms和WebForms中,您可以:

txtName.BackColor = Color.Aqua;
Run Code Online (Sandbox Code Playgroud)


小智 6

web表单;

TextBox.Background = System.Drawing.Color.Red;
Run Code Online (Sandbox Code Playgroud)