[英]How to make a textbox visible if last item in a combobox is selected c#
I have combobox9,textBox4 and textBox15 in a winform.我在 winform 中有 combobox9、textBox4 和 textBox15。 By default, textBox15 is hidden.默认情况下,textBox15 是隐藏的。
What i'm trying to do.我正在尝试做的事情。
If textbox4 backcolor is red and the last item in combobox9 is selected, then show textbox15.如果 textbox4 的背景颜色为红色,并且选择了 combobox9 中的最后一项,则显示 textbox15。
if (comboBox9.SelectedIndex == comboBox9.Items.Count - 1 && textBox4.BackColor == Color.Red) ;
{
textBox15.Visible = true;
textBox15.BackColor = Color.Red;
}
else
{
textBox15.Visible = false;
}
No errors, it just doesn't work as expected.没有错误,它只是没有按预期工作。 It keeps the textbox hidden even when the conditions are satisfied.即使满足条件,它也会隐藏文本框。 Any leads?有什么线索吗?
You should put all your code in your SelectedIndexChanged
event of your combobox您应该将所有代码放在 combobox 的SelectedIndexChanged
事件中
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
{
label1.Visible = true;
}
else
{
label1.Visible = false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.