tags:

views:

228

answers:

1

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  A: 

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

Rectangle screenRectangle=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.

Ash
I believe this is the better solution. SystemInformation.CaptionHeight will only give the Title Bar height for a top level window (I believe), and would not work for ToolWindows, so this is a little more generic.
Nick
Thanks, by PointToScreen do you mean RectangleToScreen? I am not sure, so just wondering.
Joan Venge
+1 from me, I too believe this is the better solution. 'SystemInformation.CaptionHeight' does not seem to work with ToolWindows.
Jay Riggs
@Joan, you're right, I've fixed the answer. PointToScreen is handy to know too.
Ash
Thanks, I am actually surprised that Form doesn't have a property like TitleHeight or something.
Joan Venge
@Joan, yes that would be handy, but WinForms gives us very little when it comes to the non-client area of forms (ie the Titlebar and form borders).
Ash
Thanks Ash, you are right :)
Joan Venge
I'm not so sure this is correct. Aero lies about the window position for appcompat reasons. Its fat borders are a tricky problem.
Hans Passant
Hmm I didn't think about this. So you think there is no way to do this? I am really surprised then.
Joan Venge