我沒有做過任何MDI的東西,而是從快速playaround我相信這可能幫助。我將下面的內容放入子表單中。
label1.Text = this.Parent.ClientRectangle.Width.ToString() + "x" + this.Parent.ClientRectangle.Height.ToString();
它似乎返回MDI父級的內部大小。當我添加更多的工具條和狀態條時,高度降低了。
希望這會有所幫助。
編輯: 奇怪,這似乎並沒有帶回父窗體名稱(HMM一個謎):
label1.Text = this.Parent.Name;
編輯2: 但這(注意第2父 - 我現在很困惑):
label1.Text = this.Parent.Parent.Name;
編輯3: 好吧,一對夫婦經過更多的測試...
1. this.Parent.ClientRectangle //this seems to be the size in the MDI form - NOT including toolbars/statusstrips/menustrips etc.
2. this.Parent.Parent.ClientRectangle //Having TWO parents seems to be the main MDI size - no matter how many strips added in this seems to return the size - not including the window titlebar.
道歉的編輯。
FindForm()如何? http://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform.aspx – Tom 2011-06-01 10:44:09
我試過「var f = this.FindForm();」初始在子窗體上,但它只是返回ChildForm細節而不是父窗體。我認爲FindForm只適用於控件。 – harag 2011-06-01 10:56:31