Coordinate System for Windows

These days have been watching Charles Petzold's Programming in the Microsoft Windows with C #, there are many details of stuff, and so even the novice can easily get confused or wrong, so make a summary. This article focuses on the coordinate system under Windows and represents a point in different coordinate systems.

There are three coordinates (if you count the Desktop Coordinate, then that is four kinds of) under Windows:
1. Coordinate Client: point coordinates are relative to the upper left corner of the client area concerned
2. Form Coordinate: coordinate point relative to Form for the top left corner
3. screen coordinate: coordinate point is the top left corner of the screen in terms relative to the

Desktop coordinate and screen coordinate is the same in most cases, but if the task bar is on the left or on top of the words will be different (if the left X Sreen > X Desktop, the same if the upper side y Screen > y Desktop ).

OK, let's look at how to convert in different coordinate systems. We note that there are notes System.Windows.Forms.Control.Location properties of the .NET Framework in so many words: If a Control Form, then the Location property value represents the upper left corner of the Form (in screen coordinates). Therefore, coordinates of the Coordinate To Screen (X Screen , YScreen ) into coordinates (x in the Coordinate Form1 form , Y form ), the following equation:
X Screen = X form + location.x
Y Screen = Y form + location.y


Also note that the System.Windows .NET Framework. Remarks Forms.Form.DesktopLocation attribute words: screen-based desktop coordinates the work area, the area does not include the taskbar. We can Desktop Coordinate the coordinates (X Desktop , Y Desktop ) and Form Coordinate at coordinates (X form , Y form ) each conversion:
X Desktop = X form + DesktopLocation.X
Y Desktop = Y form + DesktopLocation.Y

For about algebra can be converted to each other between the Desktop Coordinate and Screen Coordinate:
X Desktop = X Screen + DesktopLocation.X - location.x
Y Desktop  = Y Screen + DesktopLocation.Y - location.y


To lower the Client Coordinate then each coordinate conversion to have a method by way of example and PointToScreen Control PointToClient coordinates of the coordinates of the Client Screen coordinate interchangeable under coordinate, then using the above formula further converted.

Reproduced in: https: //www.cnblogs.com/mcliu/archive/2006/02/17/332856.html

Guess you like

Origin blog.csdn.net/weixin_33920401/article/details/93930012