Panel中动态生成控件清理问题(我的问题一向100分)
程序中的主Form中有一个主Panel,Panel中的控件是根据配置文件动态生成。选择不同的交易生成不同的界面。生成新界面前要清理原来的一些控件,可是在清理时出现部分控件未清理掉的问题。请问为什么?谢谢!
部分代码如下:
void ScoClassInterface::InitUI( MenuItem__* mi,Panel* pl)
{
Label* lb;
pl->SuspendLayout( );
// 清理上个界面的控件
IEnumerator* en = pl->Controls->GetEnumerator( );
while( en->MoveNext( )) {
if( pl->Controls->Contains(dynamic_cast<Control*>(en->Current))) {
pl->Controls->Remove( dynamic_cast<Control*>(en->Current));
}
}
......
while( line = sr->ReadLine( )) {
line->Trim( );
if( line->Length == 0)
continue;
if( line->Equals(S"[DATFIELD]"))
break;
split = line->Split(delimiter);
lb = new System::Windows::Forms::Label();
int y = (int)Convert::ToInt32(split[2])*17;
int x = (int)Convert::ToInt32(split[3])*10;
lb->Location = Point( x, y);
lb->Text = split[1];
lb->Size = System::Drawing::Size( 100, 16);
pl->Controls->Add(lb);
}
......