How to get the size of a Winforms Form titlebar height?

后端 未结 5 556
独厮守ぢ
独厮守ぢ 2021-02-01 01:59

So if it\'s toolwindow or a minimizable form, I want to be able to get its height programmatically.

Is this possible? If so how?

5条回答
  •  灰色年华
    2021-02-01 02:34

    There is an additional wrinkle in case your form is a view in an MDI application. In that case RectangleToScreen(this.ClientRectangle) returns coordinates relative not to Form itself (as one might expect) but with respect to MainForm which hosts MDIClient control hosting the Form.

    You may to account for that by

    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;
    

提交回复
热议问题