gpt4 book ai didi

c# - 从另一个表单显示一个表单

转载 作者:太空狗 更新时间:2023-10-30 00:17:19 24 4
gpt4 key购买 nike

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

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

或者我与“所有者”一起工作:

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

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

最佳答案

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

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。如果您不想要这种行为,请不要使用它。

关于c# - 从另一个表单显示一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2618830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com