SubZeroFX
SubZeroFX

Reputation: 490

How to change TextBox's Background color?

I got C# code that is like:

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

How to change TextBox's background color?

Upvotes: 10

Views: 147268

Answers (6)

Geeking
Geeking

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

Nav
Nav

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

Randhi Rupesh
Randhi Rupesh

Reputation: 15090

in web application in .cs page

   txtbox.Style.Add("background-color","black");

in css specify it by using backcolor property

Upvotes: 3

Marius Bancila
Marius Bancila

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

Emre
Emre

Reputation: 573

webforms;

TextBox.Background = System.Drawing.Color.Red;

Upvotes: 7

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 15158

In WinForms and WebForms you can do:

txtName.BackColor = Color.Aqua;

Upvotes: 21

Related Questions