Windows 窗体坐标Windows Forms Coordinates

Windows 窗体坐标系统基于设备坐标,并度量值时在 Windows 窗体中绘制的基本单位是设备单元 (通常情况下,像素)。The coordinate system for a Windows Form is based on device coordinates, and the basic unit of measure when drawing in Windows Forms is the device unit (typically, the pixel). 在屏幕上的点的 x 坐标和 y 坐标对所述增加到右侧和 y 坐标增加从顶部到底部的 x 坐标。Points on the screen are described by x- and y-coordinate pairs, with the x-coordinates increasing to the right and the y-coordinates increasing from top to bottom. 来源,相对于屏幕中,位置将有所不同具体取决于是否指定屏幕或客户端坐标。The location of the origin, relative to the screen, will vary depending on whether you are specifying screen or client coordinates.

屏幕坐标Screen Coordinates

Windows 窗体应用程序指定屏幕坐标中的屏幕上窗口的位置。A Windows Forms application specifies the position of a window on the screen in screen coordinates. 屏幕坐标的来源是屏幕的左上角。For screen coordinates, the origin is the upper-left corner of the screen. 窗口的完整位置通常由Rectangle结构,它包含两个定义窗口的左上角和右下角的点的屏幕坐标。The full position of a window is often described by a Rectangle structure containing the screen coordinates of two points that define the upper-left and lower-right corners of the window.

客户端坐标Client Coordinates

Windows 窗体应用程序窗体或控件使用客户端坐标中指定的点的位置。A Windows Forms application specifies the position of points in a form or control using client coordinates. 工作区坐标中的源是控件或窗体的工作区的左上角。The origin for client coordinates is the upper-left corner of the client area of the control or form. 客户端坐标可确保在应用程序可以在窗体或控件,无论窗体或屏幕上的控件的位置中绘制时使用一致的坐标值。Client coordinates ensure that an application can use consistent coordinate values while drawing in a form or control, regardless of the position of the form or control on the screen.

客户端区域的尺寸,还介绍了由Rectangle结构,其中包含工作区坐标中的区。The dimensions of the client area are also described by a Rectangle structure that contains client coordinates for the area. 在所有情况下,矩形的左上角的坐标包含在客户端区域中,,而不对此右下角坐标。In all cases, the upper-left coordinate of the rectangle is included in the client area, while the lower-right coordinate is excluded. 图形操作不包括的客户端区域的上边缘右和下边缘。Graphics operations do not include the right and lower edges of a client area. 例如FillRectangle方法将一直填充到指定的矩形的上边缘右和下边缘,但不是会包括这些边缘。For example the FillRectangle method will fill up to the right and lower edge of the specified rectangle, but will not include these edges.

将映射到另一种类型的坐标从Mapping From One Type of Coordinate to Another

有时,你可能需要从屏幕坐标映射到客户端坐标。Occasionally, you may need to map from screen coordinates to client coordinates. 你可以轻松地实现此目的使用PointToClientPointToScreen方法中提供Control类。You can easily accomplish this by using the PointToClient and PointToScreen methods available in the Control class. 例如,MousePosition属性Control报告在屏幕坐标中,但你可能想要将它们转换成工作区坐标。For example, the MousePosition property of Control is reported in screen coordinates, but you may want to convert these to client coordinates.

请参阅See Also

PointToClient
PointToScreen