开发者

Communicating between forms

开发者 https://www.devze.com 2023-02-18 18:13 出处:网络
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 f

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消