本文介绍了当焦点输入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时,如何更改所有文本框的背景颜色
发布评论