Search code examples
c#.netwinforms

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


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?


Solution

  • 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.