请问这里有什么问题
abc = labGuns.Text; // multiline label
string[] arr = Regex.Split(abc, "\r\n");
x = 0;
foreach (string line in arr)
{
MessageBox.Show(line); //works fine - shows each line of label
x = x + 1;
string abc = "cbGuns" + x.ToString();
MessageBox.Show(abc); //works fine - shows "cbGuns1", "cbGuns2"...
foreach (Control c in panPrev.Controls)
{
if (c.Name == abc) // five combos named cbGuns1, cbGuns2...
{
c.Text = line; //doesn't work. No combo changes its text
}
}
}
如果我将最后一行更改为 - c.Text = "323"
- 也没有发生任何事情。
因此,错误显然在代码末尾附近。
此代码也有效(作为测试):
foreach (Control c in panPrev.Controls)
{
if (c.Name == "cbGuns1")
{
c.Text = "323";
}
}