我目前正在使用文本框上的可見屬性。下面我複製/粘貼我的代碼片段。當窗體被加載時,我總共有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