如何从其他表单实例化MDI父级 [英] How to instantiate MDI parent from other form

查看:57
本文介绍了如何从其他表单实例化MDI父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我只是想问一下如何在我的Form1上实例化或调用我的MDI父级。我的代码看起来像这样。



Form2 frm2 = new Form2();

frm2.MdiParent = this; -------->这是我想在我的Form2上实例化的那个

frm2.Show();



我的问题是我想要实例化这部分是关于我在另一种形式上的MDIParent的语法。感谢你们。期待回复。

Hi Guys, I just want to ask how to instantiate or call my MDI parent on my Form1. My codes look like this.

Form2 frm2 = new Form2();
frm2.MdiParent = this; --------> this is the one that I want to instantiate on my Form2
frm2.Show();

My problem is I want to instantiate the this part on my syntax on MDIParent on the other form. Thank you guys. Looking forward for the reply.

推荐答案

重新加入的代码:Form2代码

Codes for reattch: Form2 Codes
//Instantiating Form1
Form1 frm1 = new Form1();
this.MdiParent = frm1;



每当我重新连接时,这都是问题孩子没有任何反应。



不,它不会。

因为你正在重新连接Form1的实例不是原始的,甚至不显示 - 这是一个完全不同的实例!关键字 new 在这里应该为您提供一个线索。 :笑:



这就像一辆车:如果你把手机放在汽车的手套箱里,然后把它卖给买一辆新车,你会期待吗?在新车手套箱中找到你的手机?



当你分离form2时,要么保存Parent实例并使用该实例进行重新连接,要么更好在Form2中创建一个事件,要求父母分离并重新附加表单。这样,form2不需要知道它的父级。


this is the problem whenever I reattach the child form nothing happens.

No, it won't.
Because the instance of Form1 that you are "reattaching" to is not the original, and is not even displayed - it is a totally different instance! The keyword new here should give you a clue about this. :laugh:

It's like a car: if you put your mobile phone in the glove box of your car, and sell it to buy a new car, would you expect to find your phone in the new cars glove box?

When you "detach" the form2, either save the Parent instance and use that instance for reattaching, or better still create a events within Form2 which ask the Parent to detach and reattach the form. That way, form2 does not need to know about it's parent.


这篇关于如何从其他表单实例化MDI父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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