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

后端 未结 5 506
独厮守ぢ
独厮守ぢ 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:26

    You can determine titlebar height for both tool-windows and normal forms by using:

    Rectangle screenRectangle = this.RectangleToScreen(this.ClientRectangle);
    
    int titleHeight = screenRectangle.Top - this.Top;
    

    Where 'this' is your form.

    ClientRectangle returns the bounds of the client area of your form. RectangleToScreen converts this to screen coordinates which is the same coordinate system as the Form screen location.

提交回复
热议问题