从另一个表单显示一个表单 [英] Show a form from another form

查看:39
本文介绍了从另一个表单显示一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想通过单击另一个表单中的按钮来显示一个表单 (C#) 时,我通常从要显示的表单创建一个对象并使用 show 方法:

When I want to Display a form (C#) by clicking a button in another form I usually create an object from the form that I want to show and use the show method :

        Form2 f2 = new Form2();
        f2.Show();

或者我与所有者"合作:

or I work with the "Owner" :

        Form2 tempForm = new Form2();
        this.AddOwnedForm(tempForm);
        tempForm.Show();

两种方式产生相同的结果,但什么是最好的,它们之间有什么区别?

the two ways generate the same results but what is the best and what are the differences between them?

推荐答案

除了命名之外的唯一区别是在第二个调用 AddOwnedForm,在第一个你没有.查看我们看到的文档:

The only difference apart from the naming is that in the second you call AddOwnedForm, and in the first you do not. Looking at the documentation we see:

当一个表单被另一个表单拥有时,它会被最小化并与所有者表单一起关闭.例如,如果 Form2 归 Form1 所有,如果 Form1 关闭或最小化,则 Form2 也关闭或最小化.拥有的表单也永远不会显示在其所有者表单的后面.You can use owned forms for windows such as find and replace windows, which should not be displayed behind the owner form when the owner form is selected.

When a form is owned by another form, it is minimized and closed with the owner form. For example, if Form2 is owned by form Form1, if Form1 is closed or minimized, Form2 is also closed or minimized. Owned forms are also never displayed behind their owner form. You can use owned forms for windows such as find and replace windows, which should not be displayed behind the owner form when the owner form is selected.

因此,如果您希望表单的这种行为一起最小化,并且一个总是显示在另一个之上,请使用 AddOwnedForm.如果您不想要这种行为,请不要使用它.

So if you want this behavior of the forms being minimized together, and one always being shown above the other, use AddOwnedForm. If you don't want this behavior, don't use it.

这篇关于从另一个表单显示一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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