Point.X 属性

获取或设置此 Point 的 X 坐标。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public Property X As Integer
用法
Dim instance As Point
Dim value As Integer

value = instance.X

instance.X = value
public int X { get; set; }
public:
property int X {
    int get ();
    void set (int value);
}
/** @property */
public int get_X ()

/** @property */
public void set_X (int value)
public function get X () : int

public function set X (value : int)

属性值

Point 的 X 坐标。

示例

下面的代码示例演示如何使用 op_Equality 运算符以及如何从 Size 或两个整数构造 Point。此示例还演示如何使用 XY 属性。此示例是针对使用 Windows 窗体而设计的。将代码粘贴到一个窗体中(该窗体包含一个名为 Button1 的按钮),然后将 Button1_Click 方法与该按钮的 Click 事件关联。

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Construct a new Point with integers.
    Dim Point1 As New Point(100, 100)

    ' Create a Graphics object.
    Dim formGraphics As Graphics = Me.CreateGraphics()

    ' Construct another Point, this time using a Size.
    Dim Point2 As New Point(New Size(100, 100))

    ' Call the equality operator to see if the points are equal,  
    ' and if so print out their x and y values.
    If (Point.op_Equality(Point1, Point2)) Then
        formGraphics.DrawString(String.Format("Point1.X: " & _
            "{0},Point2.X: {1}, Point1.Y: {2}, Point2.Y {3}", _
            New Object() {Point1.X, Point2.X, Point1.Y, Point2.Y}), _
            Me.Font, Brushes.Black, New PointF(10, 70))
    End If

End Sub
private void Button1_Click(System.Object sender, System.EventArgs e)
{

    // Construct a new Point with integers.
    Point Point1 = new Point(100, 100);

    // Create a Graphics object.
    Graphics formGraphics = this.CreateGraphics();

    // Construct another Point, this time using a Size.
    Point Point2 = new Point(new Size(100, 100));

    // Call the equality operator to see if the points are equal,  
    // and if so print out their x and y values.
    if (Point1 == Point2)
    {
        formGraphics.DrawString(String.Format("Point1.X: " +
            "{0},Point2.X: {1}, Point1.Y: {2}, Point2.Y {3}",
            new object[]{Point1.X, Point2.X, Point1.Y, Point2.Y}),
            this.Font, Brushes.Black, new PointF(10, 70));
    }

}
private:
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Construct a new Point with integers.
      Point Point1 = Point(100,100);

      // Create a Graphics object.
      Graphics^ formGraphics = this->CreateGraphics();

      // Construct another Point, this time using a Size.
      Point Point2 = Point(System::Drawing::Size( 100, 100 ));

      // Call the equality operator to see if the points are equal,  
      // and if so print out their x and y values.
      if ( Point1 == Point2 )
      {
         array<Object^>^temp0 = {Point1.X,Point2.X,Point1.Y,Point2.Y};
         formGraphics->DrawString( String::Format( "Point1.X: "
         "{0},Point2.X: {1}, Point1.Y: {2}, Point2.Y {3}", temp0 ), this->Font, Brushes::Black, PointF(10,70) );
      }
   }
private void button1_Click(Object sender, System.EventArgs e)
{
    // Construct a new Point with integers.
    Point point1 = new Point(100, 100);

    // Create a Graphics object.
    Graphics formGraphics = this.CreateGraphics();

    // Construct another Point, this time using a Size.
    Point point2 = new Point(new Size(100, 100));

    // Call the equality operator to see if the points are equal,  
    // and if so print out their x and y values.
    if (point1.Equals(point2)) {
        formGraphics.DrawString(String.Format("Point1.X: " 
            + "{0},Point2.X: {1}, Point1.Y: {2}, Point2.Y {3}", 
            new Object[] { new Integer(point1.get_X()), 
            new Integer(point2.get_X()), new Integer(point1.get_Y()), 
            new Integer(point2.get_Y())    }), this.get_Font(),
            Brushes.get_Black(), new PointF(10, 70));
    }
} //button1_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Point 结构
Point 成员
System.Drawing 命名空间