2016-05-13 156 views
1

如何將Form1,父窗體設置爲另一窗體Form2,以便我可以使用Form2.StartPosition = FormStartPosition.CenterParent;將窗體設置爲父窗體#

+0

如果使用'ShowDialog'來顯示Form2,則Form1是Form2的父對象。或者你可以使用'Show(this)' – Pikoh

回答

0

爲了打開窗體2爲孩子Form1中使用代碼:

在Form1

Form2 fr=new Form2(); 
fr.Parent=this; 
fr.show(); 

或使用:

Form2 fr=new Form2(); 
fr.show(this); 
0
loginForm.StartPosition = FormStartPosition.CenterParent; 
loginForm.ShowDialog(this); 

當然,孩子現在會父窗口的阻止窗體(對話框),如果不需要,那麼只需將ShowDialog替換爲Show ..

loginForm.Show(this); 

雖然你仍然需要指定StartPosition。