I have a main form from which I generate multiple subforms. I store these forms in a List<Subform^> ^
variable so that I can send messages to them from the main 开发者_开发百科form. I load new forms like this (from memory, might not compile):
Subform ^sf = gcnew Subform(some, variables, here);
subforms->Add(sf);
subforms[subforms.Count-1]->Show();
My goal is to remove the subform from the list once it's closed. I've been considering moving to a dictionary for simpler form identification, like this:
++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();
How would I remove the ith form when closing? Perhaps something like this (in pseudocode)
sf->FormClosed = subforms->RemoveAt[i]; // Before I add it to the dictionary.
?
Try something like:
sf->FormClosed += gcnew FormClosedEventHandler(this, &RemoveSubform);
void RemoveSubform(System::Object^ sender, FormClosedEventArgs^ e)
{
subforms->Remove(sender);
}
精彩评论