2011-06-01 75 views
0

我剛剛爲客戶設計了一個商業信息儀表板。最初的設計是用於1280x1024屏幕分辨率,但現在看來客戶的分辨率爲1024 x 768。這個BI表單是一個MDI界面的子窗口,因此有一個標題和狀態欄,這意味着如果應用程序已被全部佔用,那麼它佔用1024/768 - Windows任務欄,我的表單具有此可用大小減去標題和MDI應用程序的狀態欄。我可以處理這個問題,但我想讓應用程序專門針對最常用的屏幕大小進行定製,而這正是他的做法。如何測量表單的尺寸?

有沒有人知道任何地方的註冊表或任何工具等可以告訴我窗口/窗體的大小,因爲它正在查看?

乾杯 添

回答

0

我沒有做過任何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. 

道歉的編輯。

+0

FindForm()如何? http://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform.aspx – Tom 2011-06-01 10:44:09

+0

我試過「var f = this.FindForm();」初始在子窗體上,但它只是返回ChildForm細節而不是父窗體。我認爲FindForm只適用於控件。 – harag 2011-06-01 10:56:31