views:

23

answers:

1

I'm trying to untangle all the position and dimension properties of winforms, and it would be really helpful if there were a comprehensive overview explaining the relationships between them. Many of them appear to be functionally equivalent, but I'm concerned I may be making some false assumptions.

For reference, I am referring to properties such as Screen.PrimaryScreen.Bounds vs Form.DesktopBounds; Form.ClientRectangle vs Form.DisplayRectangle; Form.left vs Form.Location.X; PointToScreen vs Cursor.Position, and so forth. I'm also particularly interested in the effect of multiple monitors on the position properties.

If anyone knows of an annotated diagram laying this all out, that would be awesome.

+3  A: 

As a partial answer, describing those properties you list above:

  • Screen.PrimaryScreen.Bounds gives you the dimensions for the main monitor. On a multi-monitor setup that is whichever screen is set as primary.
  • Form.DesktopBounds gives you the combined boundary for the entire "desktop", which is a virtual canvas spanning all active monitors.
  • Form.ClientRectangle provides the area (rect) of the client area of the form (the space inside the chrome)
  • Form.DisplayRectangle is similar to Form.ClientRectangle but includes the chrome (title bar and border around form)
  • Form.Location.X and Form.Left are effectively the same thing (also applies to top and Y) using top-left as 0,0 origin and increasing x and y towards the bottom right
  • PointToScreen returns the "screen" coordinate - but seems to be relative to the total desktop area; Cursor.Position returns a similar value

If you're wanting to learn more about the screen configuration on the client then check out the Screen class on MSDN. Of some interest might also be the AllScreens property, which gives you details on the full setup.

Edit:

Ok - a (simple) overview ;-) I can be lazy too!

Simple Overview of Position Properties

AJ
@AJ - thanks, but just to clarify I wasn't looking for individual explanations. As lazy as I may be, I did go MSDN spelunking. What I was really hoping for an overview that tied them all together - preferably an annotated diagram.
Nick Hebb
Ok... a little picture for you :) Maybe a little helpful, but the full list... *sigh* I can only hope my image inspires someone with more time!
AJ
@AJ - dude, you rock!
Nick Hebb