WinForm 子窗體居中於父窗體代碼


可以通過子窗體的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的意思並不是屏幕居中(是相對的),它是在"當前顯示窗口"中居中。

本文轉載自柯樂義http://www.keleyi.com/dev/beb40909418eb322.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM