本文介绍了知道子表单何时关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带按钮的 Form1.当你点击按钮时,这个代码块会执行:

I've a Form1 with a button. When you click the button, this code block executes:

Form2 frm = new Form2();
frm.Name = "Form" + musteriNumarasi.ToString();
frm.Text = "Kullanıcı - " + musteriNumarasi.ToString();

假设我点击了 3 次.现在有四种形式:Main、Child1、Child2、Child3.当用户关闭其中一个子窗体时,主窗体需要知道关闭的是哪一个.我该怎么做?

Lets say I've clicked three times. There are four forms now: Main, Child1, Child2, Child3. When user closes one of the child forms, main form needs to know which one is closed. How can I do that?

推荐答案

订阅 Closed Event

Form2 frm = new Form2();    
frm.FormClosed += new FormClosedEventHandler(Form_Closed);

void Form_Closed(object sender, FormClosedEventArgs e)
{
    Form2 frm = (Form2)sender;
    MessageBox.Show(frm.Name);
}

这篇关于知道子表单何时关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:47