关闭子窗体时如何在父窗体中运行方法 [英] How run a method in parent Form when closing child Form

查看:125
本文介绍了关闭子窗体时如何在父窗体中运行方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序员,

我有两种Windows形式:form1 form2.
关闭form2时,我要启动form1 中的方法form_load .

Hi programmers,

I have two Windows forms: form1 and form2.
When closing form2, I want method form_load in form1 to start. How can I do this????

推荐答案

我认为这就是您想要的:

在from1中写道:

I think this is what you want:

in from1 write this:

public void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("hi");
        }



并在from2中这样写:



and in from2 write this:

private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
    Form1 frm = new Form1();
    frm.Form1_Load(sender,e);

}



希望对您有所帮助:)



hope it helps :)


您可以尝试以下操作:

form2form_closed事件中,输入:

You can try this:

In the form_closed event of form2, write:

Form1 frm1 = new Form1(); 
frm1.ShowDialog(); 



希望这可以帮助. :)



Hope this helps. :)


顾名思义,此方法是虚拟"事件Load的处理程序. 您永远不要直接调用它!,它会弄乱事情.您是否只需要显示其他表格?实例化表单类并显示实例?您想做的事没有任何意义.

如果您解释了它的目的,那么您可能会得到关于如何做的建议.

—SA
As the name suggests, this method is the handler of the "fictive" event Load. You should never call it directly!, it will mess-up things. Do you simply need to show another form? Instantiate form class and show instance? What you want to do makes no sense.

If you explain the purpose of it, you might get an advice on what to do.

—SA


这篇关于关闭子窗体时如何在父窗体中运行方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆