问题
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.
回答1:
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 toForm.ClientRectangle
but includes the chrome (title bar and border around form)Form.Location.X
andForm.Left
are effectively the same thing (also applies to top and Y) using top-left as 0,0 origin and increasingx
andy
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!
来源:https://stackoverflow.com/questions/3684725/winforms-position-and-dimension-properties