Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change TextBox's Background color?

Tags:

c#

.net

wpf

I got C# code that is like:

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

How to change TextBox's background color?

like image 689
SubZeroFX Avatar asked May 25 '13 06:05

SubZeroFX


3 Answers

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;
like image 158
Marius Bancila Avatar answered Sep 27 '22 15:09

Marius Bancila


In WinForms and WebForms you can do:

txtName.BackColor = Color.Aqua;
like image 25
Dimitar Dimitrov Avatar answered Sep 27 '22 15:09

Dimitar Dimitrov


webforms;

TextBox.Background = System.Drawing.Color.Red;
like image 36
Emre Avatar answered Sep 27 '22 15:09

Emre