单击组合框时,文本框的颜色发生变化 [英] text box color change when click the combobox
本文介绍了单击组合框时,文本框的颜色发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我解决这个问题吗
当我从组合框中选择一个项目时,当数量小于5时,如何更改文本框的底色(用于显示数量).
Can any body help me to solve this
when i select a item from combobox how can i change the back color of my text box(used to show quantity) when the quantity became less than 5 .
推荐答案
''与我以前的答案基本相同:(数量取自文本框,也可以通过将textBox2.Text
替换为comboBox1.SelectedItem.ToString()
来取自组合框)
That'' basically the same as my previous answer: (quantity is taken from the textBox, but can also be taken from the combobox by replacingtextBox2.Text
withcomboBox1.SelectedItem.ToString()
)
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int quantity = 0;
if (!Int32.TryParse(textBox2.Text, out quantity))
{
textBox2.BackColor = Color.Red;
return;
}
if (quantity < 5)
textBox2.BackColor = Color.Green;
else
textBox2.BackColor = Color.White;
}
这篇关于单击组合框时,文本框的颜色发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文