Point 构造函数

定义

使用指定坐标初始化 Point 结构的新实例。

重载

Point(Size)

Size 初始化 Point 结构的新实例。

Point(Int32)

使用由整数值指定的坐标初始化 Point 结构的新实例。

Point(Int32, Int32)

使用指定坐标初始化 Point 结构的新实例。

Point(Size)

Source:
Point.cs
Source:
Point.cs
Source:
Point.cs

Size 初始化 Point 结构的新实例。

public:
 Point(System::Drawing::Size sz);
public Point (System.Drawing.Size sz);
new System.Drawing.Point : System.Drawing.Size -> System.Drawing.Point
Public Sub New (sz As Size)

参数

sz
Size

Size,它指定新 Point 的坐标。

示例

下面的代码示例演示如何使用 Equality 运算符以及如何从一Size个或两个Point整数构造 。 它还演示如何使用 XY 属性。 此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到包含名为 的 Button1按钮的窗体中 Button1_Click ,并将 方法与按钮的 Click 事件相关联。

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(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 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

适用于

Point(Int32)

Source:
Point.cs
Source:
Point.cs
Source:
Point.cs

使用由整数值指定的坐标初始化 Point 结构的新实例。

public:
 Point(int dw);
public Point (int dw);
new System.Drawing.Point : int -> System.Drawing.Point
Public Sub New (dw As Integer)

参数

dw
Int32

一个 32 位整数,它指定新 Point 的坐标。

示例

下面的代码示例演示如何使用 PointSize.Size 构造函数和 System.Drawing.ContentAlignment 枚举。 若要运行此示例,请将此代码粘贴到包含名为 的 Label1标签的 Windows 窗体中,并在窗体的构造函数中调用 InitializeLabel1 方法。

void InitializeLabel1()
{
   // Set a border.
   Label1->BorderStyle = BorderStyle::FixedSingle;
   
   // Set the size, constructing a size from two integers.
   Label1->Size = System::Drawing::Size( 100, 50 );
   
   // Set the location, constructing a point from a 32-bit integer
   // (using hexadecimal).
   Label1->Location = Point(0x280028);
   
   // Set and align the text on the lower-right side of the label.
   Label1->TextAlign = ContentAlignment::BottomRight;
   Label1->Text = "Bottom Right Alignment";
}
private void InitializeLabel1()
{
    // Set a border.
    Label1.BorderStyle = BorderStyle.FixedSingle;

    // Set the size, constructing a size from two integers.
    Label1.Size = new Size(100, 50);

    // Set the location, constructing a point from a 32-bit integer
    // (using hexadecimal).
    Label1.Location = new Point(0x280028);

    // Set and align the text on the lower-right side of the label.
    Label1.TextAlign = ContentAlignment.BottomRight;
    Label1.Text = "Bottom Right Alignment";
}
Private Sub InitializeLabel1()

    ' Set a border.
    Label1.BorderStyle = BorderStyle.FixedSingle

    ' Set the size, constructing a size from two integers.
    Label1.Size = New Size(100, 50)

    ' Set the location, constructing a point from a 32-bit integer
    ' (using hexadecimal).
    Label1.Location = New Point(&H280028)

    ' Set and align the text on the lower-right side of the label.
    Label1.TextAlign = ContentAlignment.BottomRight
    Label1.Text = "Bottom Right Alignment"
End Sub

注解

参数的 dw 低位 16 位指定水平 x 坐标,较高的 16 位指定新 Point的垂直 y 坐标。

适用于

Point(Int32, Int32)

Source:
Point.cs
Source:
Point.cs
Source:
Point.cs

使用指定坐标初始化 Point 结构的新实例。

public:
 Point(int x, int y);
public Point (int x, int y);
new System.Drawing.Point : int * int -> System.Drawing.Point
Public Sub New (x As Integer, y As Integer)

参数

x
Int32

该点的水平位置。

y
Int32

该点的垂直位置。

示例

下面的代码示例演示如何使用 Equality 运算符以及如何从一Size个或两个Point整数构造 。 它还演示如何使用 XY 属性。 此示例旨在与 Windows 窗体 一起使用。 将代码粘贴到包含名为 的 Button1按钮的窗体中 Button1_Click ,并将 方法与按钮的 Click 事件相关联。

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(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 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

适用于