当焦点输入C#winforms时,如何更改所有文本框的背景颜色

编程入门 行业动态 更新时间:2024-10-25 07:30:08
本文介绍了当焦点输入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时,如何更改所有文本框的背景颜色

本文发布于:2023-06-09 04:12:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/595000.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   如何更改   颜色   背景   焦点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!