Rectangle.X 对比 Rectangle.Left

Rectangle.X vs Rectangle.Left

我看到 System.Drawing.Rectangle class 有两组属性:

WidthRight的区别很明显。但我不明白 LeftTop 属性背后的原因。

这些可以与 XY 互换使用,还是我遗漏了一些明显的东西?有什么时候应该使用哪个的约定吗?

Left 纯粹是 X 属性.

的包装

Top / Y也是如此。

hakononakani 所述,它们都是 readonly - 为了设置您需要使用 XY.

的属性
Rectangle.X = Gets or sets the x-coordinate of the upper-left corner of this Rectangle structure.

Rectangle.left = Gets the x-coordinate of the left edge of this Rectangle structure.

这是 Rectangle Structure

的完整指南

Left 获取 x 坐标。但是,X 获取或设置 x 坐标。 同样适用于 TopY.

他们是一样的属性。

它用于保持对 Visual Basic 的熟悉。

旧版本的 Visual Basic(包括 VB6)仅使用 Top 和 Left 属性 来操纵控件的位置。

微软来源:Form Positioning for Visual Basic 6.0 Users

In Visual Basic 6.0, the initial screen location for a form can be set at design time using the Form Layout window or by setting the Left and Top properties in the Properties window. The Left and Top properties can also be set programmatically.

Microsoft 放弃对 VB6 的支持并开发 Visual Basic .NET 后,Visual Studio 包含一个迁移向导,用于将旧项目升级到 .NET 同类项目,但该向导在转换 Left 和最佳。 (缇到 .NET 像素)