当焦点输入C#winforms时,如何更改所有文本框的背景颜色 [英] How to change the background color of all textboxes when focus enter in C# winforms

查看:274
本文介绍了当焦点输入C#winforms时,如何更改所有文本框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

i在表单中有很多文本框我想在焦点输入文本框时将背景颜色更改为当它的背景颜色变为银色或白色时



我尝试了什么:



i尝试了很多但没有找到好的东西

解决方案

处理TextBox.Enter和Leave事件:

 private void myTextBox_Enter(object sender,EventArgs e)
{
TextBox tb = sender as TextBox;
if(tb!= null)
{
tb.BackColor = Color.Silver;
}
}

private void myTextBox_Leave(object sender,EventArgs e)
{
TextBox tb = sender as TextBox;
if(tb!= null)
{
tb.BackColor = Color.White;
}
}


hello guys!
i have many textboxes in a form i want to change the background color into when focus enter to a textbox and when it leaves its background color changes into silver or white

What I have tried:

i tried a lot but didn't find something good

解决方案

Handle the TextBox.Enter and Leave events:

private void myTextBox_Enter(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        tb.BackColor = Color.Silver;
        }
    }

private void myTextBox_Leave(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        tb.BackColor = Color.White;
        }
    }


这篇关于当焦点输入C#winforms时,如何更改所有文本框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆