winforms position and dimension properties

北慕城南 提交于 2020-01-02 03:40:11

问题


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 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!



来源:https://stackoverflow.com/questions/3684725/winforms-position-and-dimension-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!