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?
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?
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.
In my case, I had to change the height of the form so that it was just below one of the controls, I noticed that
int titleHeight = this.Height - screenRectangle.Height;
returns 39 while the accepted answer:
int titleHeight = screenRectangle.Top - this.Top;
returns 31
maybe because of form's bottom border.
To fix S. Norman's answer that simply has his minuend and subtrahend switched, the following is the simplest answer:
int HeightOfTheTitleBar_ofThis = this.Height - this.ClientRectangle.Height;
BTW, the standard hard coded title bar is 25dpi which is the minimum height and can be changed to a maximum of 50dpi.
OK OK,... yes, it is technically incorrect As stated by Cody Grey but it works and should get the same answer as the accepted answer. No need to create a rectangle.