简体   繁体   中英

Rectangle.X vs Rectangle.Left

I see that the System.Drawing.Rectangle class has two sets of properties:

  • X , Y , Width , Height
  • Left , Top , Right , Bottom

The difference between Width and Right are obvious. But I don't understand the reasoning behind the Left and Top properties.

Can these be used interchangeably along with X and Y , or am I missing something obvious? Is there a convention for when I should use which?

Left is purely a wrapper around the X property.

The same goes for Top / Y .

As noted by hakononakani , they are both readonly - in order to set the properties you need to use X and Y .

Left only gets the x-coordinate. However, X gets or sets the x-coordinate. Same applies to Top and Y .

They are the same property.

It is there to maintain familiarity with Visual Basic.

Old versions of Visual Basic (including VB6) only used Top and Left property to manipulate positions of controls.

Microsoft source: 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.

After Microsoft dropped VB6 support and made Visual Basic .NET, Visual Studio included an migration wizard to upgrade old projects to .NET cousins, but that wizard continued to use old properties while converting numeric values of Left and Top. (Twips to .NET Pixels)

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.

Here is the complete guide for Rectangle Structure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM