[.net] Getting client area of a window.

Started by
4 comments, last by Rob Loach 18 years, 7 months ago
This seems like it'd be the easiest thing to do but I've looked through the docs and googled it and I can't figure out how to get my client area of a window. For example, I set my FormBorderstyle to System.Windows.Forms.FormBorderstyle.FixedDialog. My window (including border) has dimensions of x: 406, y: 432 but the actual drawable area is 400 by 400. I'm trying to figure out the border width. Sure, I could just take the difference of the widths (6) divide by 2 (3) and get the side (and probably bottom) borders, then subtract that from the height difference for the title bar at the top, but is this really the way that it's done? I can't imagine that there's no way to get the absolute position of the client area, or the border width/title bar height of a window. --Vic--
Advertisement
Did you try the Control.ClientRectangle Property?
Jooleem. Get addicted.
yup, for me always returns 0,0,400,400. The drawable area is 400 wide and tall, but that neither tells me the border width on each side nor the absolute screen postion of the drawable area.

--Vic--
Form1.ClientSize.Width (or .Height) should be what you want.

Just tested it. My window has a width of 616. ClientSize.Width returns 608. And I have a panel docked as client with the same size.
AP: yeah, I realize that means you have 8 pixels of non-client width, meaning your borders are 4 wide. But I want to be sure that this is the best way to get the width and height. I know it's prob not the case, but I don't want to ever assume that the side borders are just as wide as the bottom borders of the window when I calculate the width of the title bar.

--Vic--
The ClientSize or the ClientRectangle is exactly what you're looking for.
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement