想把panel中的所有TextBox,ComboBox控制,转换成Label类型
private void diversionCT()
{
Label lbl;
TextBox tbxType = new TextBox();
ComboBox cobType = new ComboBox();
foreach (Control temp in this.cpContent.Controls)
{
if (temp.GetType().Equals(tbxType))
{
lbl = new Label();
lbl.Location = (temp as TextBox).Location;
lbl.Text = (temp as TextBox).Text;
temp = lbl;
break;
}
if (temp.GetType().Equals(cobType))
{
lbl = new Label();
lbl.Location = (temp as ComboBox).Location;
lbl.Text = (temp as ComboBox).SelectedText;
temp = lbl;
break;
}
}
}
错误 13 “temp”是一个“foreach 迭代变量”,无法为它赋值 D:\NNMessageClient\NNMessageClient\NNMessageClient\FormBasicInfo .cs 95 21 NNMessageClient
谁有更好的方法啊?
private void diversionCT()
{
Label lbl;
TextBox tbxType = new TextBox();
ComboBox cobType = new ComboBox();
foreach (Control temp in this.cpContent.Controls)
{
if (temp.GetType().Equals(tbxType))
{
lbl = new Label();
lbl.Location = (temp as TextBox).Location;
lbl.Text = (temp as TextBox).Text;
temp = lbl;
break;
}
if (temp.GetType().Equals(cobType))
{
lbl = new Label();
lbl.Location = (temp as ComboBox).Location;
lbl.Text = (temp as ComboBox).SelectedText;
temp = lbl;
break;
}
}
}
错误 13 “temp”是一个“foreach 迭代变量”,无法为它赋值 D:\NNMessageClient\NNMessageClient\NNMessageClient\FormBasicInfo .cs 95 21 NNMessageClient
谁有更好的方法啊?
所以这么说,用循环遍历panel中的控制并需要改变其值就形成了一个瓶颈,这只有两种可能,微软不让改或微软没有考虑到