Getting Client Area Below Caption Bar

ElderGeek

New member
Joined
Feb 1, 2011
Messages
4
Programming Experience
10+
I am trying to get the coordinates of the client area of an MDI form. Currently I am using...

VB.NET:
Dim crect As Rectangle = Me.ClientRectangle

But the Top/Left coordinates are always 0,0. What I want are the coordinates relative to the window area. Can someone help me obtain this information?
 
In what context do you need this coordinate? It may be provided by an event, or you can get it from a screen coordinate using PointToClient method.
 
I need to notify a separate unmanaged process of the active area of the screen that is occupied by the form, but only the client area, not including the borders or caption bar. This information will be updated when the form is moved or resized.
 
The screen rectangle is the ClientRectangle with Location property set to Me.PointToScreen(Point.Empty), ie point(0,0).
 
Thanks but I solved the problem like this....

VB.NET:
     Dim g As Graphics = Me.CreateGraphics
     cliprect = g.VisibleClipBounds

Then I calculate the actual screen location of the client area and call my function like this...

VB.NET:
PutScreen(Me.Location.X + (Me.Width - cliprect.Right), Me.Location.Y + (Me.Height - cliprect.Bottom))

Thanks for your help.
 
Thanks but I solved the problem like this....
That does not give you the screen point of the client rectangle, try set Cursor.Position and you'll see. Use PointToScreen method and you're good.
The reason if you care to know, is that the clipbounds of forms Graphics object equates to its client rectangle (which is the only part a window paint itself), thus that would put you off by the bottom and left border size.
 
You are correct it doesn't, but it does give the rectangle of the client area. When I subtract the two areas I am left with the offset of the client area from the non-client area. Added to the forms x,y location, this is exactly the information I need. The key is transforming from the local coordinates to the screen coordinates.

If there is an easier way to obtain this I would be interested to learn.

Thanks again for your help.
 
but it does give the rectangle of the client area.
No, it doesn't.
If there is an easier way to obtain this I would be interested to learn.
Third times a charm; ClientArea by location PointToScreen(Point.Empty) is the screen area of the client rectangle.
 
Back
Top