表格之间的沟通

时间:2011-03-22 08:03:11

标签: winforms dictionary c++-cli

我有一个主窗体,我可以从中生成多个子窗体。我将这些表单存储在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.

1 个答案:

答案 0 :(得分:1)

尝试类似:

sf->FormClosed += gcnew FormClosedEventHandler(this, &RemoveSubform);

void RemoveSubform(System::Object^ sender, FormClosedEventArgs^ e)
{
    subforms->Remove(sender);
}