Reputation: 490
I got C# code that is like:
if(smth == "Open")
{
TextBox.Background = ???
}
How to change TextBox's background color?
Upvotes: 10
Views: 147268
Reputation: 1
Setting textbox backgroundcolor with multiple colors on single click.
Note:- using HTML and Javscript.
< input id="ClickMe_btn" onclick="setInterval(function () { ab() }, 3000);" type="button" value="ClickMe" />
var arr, i = 0; arr = ["Red", "Blue", "Green", " Orange ", "Purple", "Yellow", "Brown", "Lime", "Grey"]; // We provide array as input.
function ab()
{ document.getElementById("Text").style.backgroundColor = arr[i];
window.alert(arr[i]);
i++;
}
Note: You can change milliseconds, with setInterval 2nd parameter.
Upvotes: -3
Reputation: 1
It is txtName.BackColor = System.Drawing.Color.Red;
one can also use txtName.BackColor = Color.Aqua;
which is the same as txtName.BackColor = System.Color.Aqua;
Only Problem with System.color is that it does not contain a definition for some basic colors especially white, which is important cause usually textboxes are white;
Upvotes: -3
Reputation: 15090
in web application in .cs page
txtbox.Style.Add("background-color","black");
in css specify it by using backcolor property
Upvotes: 3
Reputation: 16338
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;
Upvotes: 23
Reputation: 15158
In WinForms and WebForms you can do:
txtName.BackColor = Color.Aqua;
Upvotes: 21