我想找到哪個文本框,我已經輸入信息到一個窗體上,並使窗體內的其餘文本框消隱和鎖定,因此沒有信息可以輸入到他們。Groupbox foreach沒有找到所有文本框
問題是當我運行代碼和調試。在循環播放時,我似乎沒有找到表單上的所有文本框。
我試圖通過嘗試查找groupbox name.equals和groupbox內的項目是否等於文本來更改foreach中的某些信息。我假定我對這些foreach語句犯了錯誤。
以下是我的代碼。
foreach (Control C in this.Controls)
{
if (C is GroupBox)
foreach (Control T in this.Controls)
{
if (T is TextBox)
{
{
if (T.Text != string.Empty && T.Name.Equals("txtlotno"))
{
txtheads.Enabled = false;
txtheads.BackColor = Color.LightGray;
GroupBoxHeads.BackColor = Color.LightSlateGray;
txtrisersgood.Enabled = false;
txtrisersgood.BackColor = Color.LightGray;
GroupBoxRisers.BackColor = Color.LightSlateGray;
}
else if (T.Text != string.Empty && T.Name.Equals("txtvingot"))
{
txtheads.Enabled = false;
txtheads.BackColor = Color.LightGray;
GroupBoxHeads.BackColor = Color.LightSlateGray;
txtrisersgood.Enabled = false;
txtrisersgood.BackColor = Color.LightGray;
GroupBoxRisers.BackColor = Color.LightSlateGray;
}
else if (T.Text != string.Empty && T.Name.Equals("txtheads"))
{
txtvingot.Enabled = false;
txtvingot.BackColor = Color.LightGray;
txtlotno.Enabled = false;
txtlotno.BackColor = Color.LightGray;
GroupBoxIngot.BackColor = Color.LightSlateGray;
txtrisersgood.Enabled = false;
txtrisersgood.BackColor = Color.LightGray;
GroupBoxRisers.BackColor = Color.LightSlateGray;
}
else if (T.Text != string.Empty && T.Name.Equals("txtrisersgood"))
{
txtvingot.Enabled = false;
txtvingot.BackColor = Color.LightGray;
txtlotno.Enabled = false;
txtlotno.BackColor = Color.LightGray;
GroupBoxHeads.BackColor = Color.LightSlateGray;
txtheads.Enabled = false;
txtheads.BackColor = Color.LightGray;
GroupBoxIngot.BackColor = Color.LightSlateGray;
}
}
}
}
}