开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜