現在、テキストボックスで表示されている属性を使用しています。以下に、コードのスニペットをコピーして貼り付けました。フォームが読み込まれるときに、合計8つのテキストボックスがfalseに設定されています。次に、それに応じてテキストボックスを表示する2つのラジオボタンがあります。1つradioButton
は最初の4つのテキストボックスを表示し、もう1つは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++;
}
}
}