我目前正在使用文本框上的可见属性。下面我复制/粘贴我的代码片段。当窗体被加载时,我总共有8个文本框设置为可见错误。然后我有两个单选按钮相应地显示文本框。一个radioButton
将显示前4个文本框,另一个将显示全部8个文本框。问题是切换回radioButton1
只显示4个文本框,它仍然会显示所有8个文本框?显示/隐藏文本框 - 可见
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
int count = 0;
int txtBoxVisible = 3;
foreach (Control c in Controls)
{
if (count <= txtBoxVisible)
{
TextBox textBox = c as TextBox;
if (textBox != null) textBox.Visible = true;
count++;
}
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
int count = 0;
int txtBoxVisible = 7;
foreach (Control c in Controls)
{
if (count <= txtBoxVisible)
{
TextBox textBox = c as TextBox;
if (textBox != null) textBox.Visible = true;
count++;
}
}
}
当我回去,只显示4个文本框,它仍然显示8? – CodingWonders90 2013-02-17 14:54:10
更新!添加了HideAllTextBox方法 – Mate 2013-02-17 14:57:04