我目前正在使用文本框上的可见属性。下面我复制/粘贴了我的代码片段。加载表单时,我总共有 8 个文本框设置为可见 false。然后我有两个相应地显示文本框的单选按钮。一个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++;
}
}
}