32
A
回答
45
您可以通過決定兩個工具窗口和正常形態標題欄高度:
Rectangle screenRectangle=RectangleToScreen(this.ClientRectangle);
int titleHeight = screenRectangle.Top - this.Top;
在哪裏「這」是你的形式。
ClientRectangle返回窗體客戶區域的邊界。 RectangleToScreen將其轉換爲與屏幕位置相同的座標系的屏幕座標。
2
如果您的表單是MDI應用程序中的視圖,那麼還有一個額外的摺痕。在這種情況下,RectangleToScreen(this.ClientRectangle)返回相對於Form本身的座標(正如人們所期望的那樣),但是相對於託管Form的MDIClient控件的MainForm。
您可以考慮通過
Point pnt = new Point(0, 0);
Point corner = this.PointToScreen(pnt); // upper left in MainFrame coordinates
Point origin = this.Parent.PointToScreen(pnt); // MDIClient upperleft in MainFrame coordinates
int titleBarHeight = corner.Y - origin.Y - this.Location.Y;
0
這將讓你的TitleBarsize:
form.ClientRectangle.Height - form.Height;
+0
不完全。這給你*非客戶區域*的高度。在實踐中,如果沒有其他非客戶區域,這可能與標題欄的高度相同,但它不一定相同。在語義上,那麼代碼是錯誤的。 – 2016-12-07 13:46:27
相關問題
- 1. 獲取SizeableToolWindow .NET表單的標題欄高度
- 2. 獲取JDialog標題欄的高度?
- 3. 如何改變訪問表單的標題欄高度?
- 4. 獲取瀏覽器寬度和高度排除工具欄和菜單大小
- 5. 更改標題高度/大小Winform
- 6. 使表格單元的大小相同(寬度/高度)不計算標題
- 7. WPF行標題寬度和列標題高度調整大小
- 8. QDockWidget標題欄高度
- 9. 我如何獲得JInternalFrame標題欄的高度?
- 10. 如何在Backbone Views中獲取大小(高度/寬度)信息?
- 11. 如何獲取windows mobile 6.5.3的下層菜單欄的高度
- 12. 獲取導航欄高度
- 13. 獲取WPF中TreeViewItem標題的高度
- 14. Android標題欄大小
- 15. 從多部分表單上傳獲取文件大小內容長度標題
- 16. 獲取列表中的最大高度
- 17. 標題欄與菜單合併 - WINFORMS
- 18. 如何獲取高度和寬度標題?
- 19. 如何獲取操作欄和通知欄的高度
- 20. 如何獲取狀態欄和軟鍵按鈕欄的高度?
- 21. 如何在Android中動態設置標題欄大小和標題大小
- 22. Swift如何獲得UIAlertController標題高度
- 23. 將幫助圖標添加到WinForms表單標題欄
- 24. 獲取X11窗口標題高度
- 25. LWUIT表單中的菜單欄高度
- 26. 降低標題欄的高度 - Sencha
- 27. 動態壁紙標題欄的高度
- 28. 檢測窗口標題欄的高度
- 29. React-Native:找到標題欄的高度
- 30. 如何在android中獲取通知欄的高度和寬度?
我相信這是更好的解決方案。 SystemInformation.CaptionHeight只會給頂層窗口的標題欄高度(我相信),並且不適用於ToolWindows,所以這是更通用的。 – Nick 2010-01-07 18:41:23
+1,我也相信這是更好的解決方案。 'SystemInformation.CaptionHeight'似乎不適用於ToolWindows。 – 2010-01-07 18:54:21
我不太確定這是否正確。由於appcompat的原因,Aero位於窗口位置。它的胖邊界是一個棘手的問題。 – 2010-01-07 20:13:16