我正在尝试查找我已在表单上输入信息的文本框,并将表单中的其余文本框设为空白并锁定,因此无法将任何信息输入其中。
问题是当我运行代码和调试时。循环浏览表单时,我似乎没有找到表单上的所有文本框。
我试图通过尝试查找 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;
}
}
}
}
}