2013-03-28 26 views
0

我有以下幾種形式:main_menu(mdicontainer),form1和form2。我能夠在MAIN_MENU 1跳轉打開由從另一個mdichild打開mdichild

form1 newMDIChild = new form1(); 

newMDIChild.MdiParent = this; 

newMDIChild.Show(); 

爲mdichild當我試圖通過

form2 newMDIChild = new form2(); 

newMDIChild.MdiParent = this.MdiParent; 

newMDIChild.Show; 

this.close(); 

它仍然打開窗口2爲非子窗體打開窗口2從Form1中MAIN_MENU的mdichild。到目前爲止我沒有找到任何解決方案。有任何想法嗎?提前致謝。

+0

請仔細閱讀[常見問題]和[提問] –

+0

你是如何推斷出'它仍然打開窗口2爲非兒童形式? –

+0

我不是在與VS安裝一臺機器,所以我不能對此進行測試,但我敢肯定,你可以在形式傳遞到'.Show(myForm的);' http://msdn.microsoft.com /en-us/library/szcefbbd.aspx – Sayse

回答

0

在您的文章,你暗示這兩種形式都是相同的父的孩子。如果是這種情況,form1的父項被設置爲正確的父項,但form2的父項將被設置爲其父項的父項。實際上,它使form2成爲產生它的對象的一個​​兄弟,而不是一個孩子。

嘗試產卵時改變

newMDIChild.MdiParent = this.MdiParent; 

newMDIChild.MdiParent = this; 

形式2.

+0

我不能使用'newMDIChild.MdiParent =這一點;'形式1,因爲Form1中不MdiContainer – user2039470

+0

你在你的代碼,否則表示。 – Nat

相關問題