Pyromancer
Pyromancer

Reputation: 2509

Highlight a textbox when there is no input

I would like to highlight a textbox when there's no input, here is my sample code

if (textBox2.Text == "")
                    {
                        MessageBox.Show("Please put your password");
                        textBox2.Focus();
                    }

I want to highlight it as it like glows, but it only set the Ibeam cursor unto the textbox, please help me, thanks in advance :)

Upvotes: 0

Views: 4310

Answers (5)

New Developer
New Developer

Reputation: 3305

Try this;

if (textBox1.Text == "")
{
    MessageBox.Show("Please put your password");
    textBox1.Focus();               
    textBox1.BorderThickness = new Thickness(2, 2, 2, 2);
    textBox1.BorderBrush = Brushes.Red;
    textBox1.Background = Brushes.Beige;                    
}

Upvotes: 1

Pranav
Pranav

Reputation: 8871

You need to Add these lines to the CSS:-

 .glow:focus {
    border-color: #6EA2DE;
    box-shadow: 0px 0px 10px #6EA2DE;
}

and in your form you can add a CssClass attribute:-

<asp:TextBox id="textBox2" CssClass="glow" runat="server"/>

Upvotes: -1

Raman
Raman

Reputation: 1376

You need to set the css border properties on focus of the textbox. Something like this:

textbox2:focus{

border-color: whatever color you want;

}

You can set whatever css properties you in this way.

Upvotes: -1

BizApps
BizApps

Reputation: 6130

Try using Winforms error provider:

if (textBox2.Text == "")
{
 errorProvider1.SetError(textBox2, "Please put your password");
 textBox2.BackColor = Color.Red; //to add high light
}

See : C# ErrorProvider

Regards

Upvotes: 1

Habib
Habib

Reputation: 223237

You can change the background color of the TextBox.

textBox2.BackColor = Color.Yellow;

Upvotes: 1

Related Questions