我有一个主窗体,可以从中生成多个子窗体。我将这些表单存储在一个List<Subform^> ^变量中,以便可以从主表单向它们发送消息。我像这样加载新表单(从内存中,可能无法编译):
Subform ^sf = gcnew Subform(some, variables, here);
subforms->Add(sf);
subforms[subforms.Count-1]->Show();我的目标是在关闭后将该子窗体从列表中删除。我一直在考虑使用字典来识别更简单的表单,如下所示:
++i; // Some sort of a form counter. to access them when closing.
Subform ^sf = gcnew Subform(some, variables, here);
subforms->Add(i, sf);
subforms[i]->Show();关闭时如何删除第i个表单?也许像这样(用伪代码)
sf->FormClosed = subforms->RemoveAt[i]; // Before I add it to the dictionary.发布于 2011-03-22 22:26:37
尝试如下所示:
sf->FormClosed += gcnew FormClosedEventHandler(this, &RemoveSubform);
void RemoveSubform(System::Object^ sender, FormClosedEventArgs^ e)
{
subforms->Remove(sender);
}https://stackoverflow.com/questions/5388326
复制相似问题