可以通過子窗體的StartPosition屬性設置。
建立兩個窗體KeleyiParentForm主窗體,KeleyiSonForm子窗體
在KeleyiParentForm類中的一個方法聲明顯示子窗體,並設置子窗體的StartPosition為FormStartPosition.CenterScreen:
KeleyiSonForm m_SonForm = new KeleyiSonForm();
m_SonForm.MdiParent = this;
m_SonForm.StartPosition = FormStartPosition.CenterScreen;
m_SonForm.Show();
附:
StartPosition屬性有如下選項,分別含義如下:
CenterParent 窗體在其父窗體中居中。
CenterScreen 窗體在當前顯示窗口中居中,其尺寸在窗體大小中指定。
Manual 窗體的位置由 Location 屬性確定。
WindowsDefaultBounds 窗體定位在 Windows 默認位置,其邊界也由 Windows 默認決定。
WindowsDefaultLocation 窗體定位在 Windows 默認位置,其尺寸在窗體大小中指定。
CenterScreen的意思並不是屏幕居中(是相對的),它是在"當前顯示窗口"中居中。
