Ash*_*Ash 58
您可以使用以下命令确定工具窗口和普通表单的标题栏高度:
Rectangle screenRectangle=RectangleToScreen(this.ClientRectangle);
int titleHeight = screenRectangle.Top - this.Top;
Run Code Online (Sandbox Code Playgroud)
你的表格在哪里'这个'.
ClientRectangle返回表单客户区的边界.RectangleToScreen将其转换为屏幕坐标,这是与窗体屏幕位置相同的坐标系.
如果您的表单是MDI应用程序中的视图,则还会有其他折痕。在那种情况下,RectangleToScreen(this.ClientRectangle)返回的坐标不是相对于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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
31091 次 |
最近记录: |