Change background color when clicked textbox in C#
I like for the textbox to change the background when the textbox has focus (if clicked with a mouse, tabbed into, etc).
I don't like the textchange method since it won't change until one character has been added.
private void txtF开发者_如何学Coo_OnGotFocus(object sender, EventArgs e)
{
txtFoo.BackColor = Color.LightYellow;
txtBar.BackColor = Color.White;
}
This doesn't seem to work for me. What am I doing wrong?
Did you also subscribe the event handler?
Like Ben said... did you subscribe to the event handler?
Is your code even executing? You can put a break point in there and check pretty easily.
You could try using the Enter event instead
private void txtFoo_Enter(object sender, EventArgs e)
{
txtFoo.BackColor = Color.LightYellow;
txtBar.BackColor = Color.White;
}
txtWFileNo.Style.Add(HtmlTextWriterStyle.BackgroundColor, "silver");
精彩评论