Point Point Point Point Constructors

定義

多載

Point(Size) Point(Size) Point(Size) Point(Size)

Point 初始化 Size 類別的新執行個體。Initializes a new instance of the Point class from a Size.

Point(Int32) Point(Int32) Point(Int32) Point(Int32)

使用由整數值指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class using coordinates specified by an integer value.

Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32)

使用指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class with the specified coordinates.

Point(Size) Point(Size) Point(Size) Point(Size)

Point 初始化 Size 類別的新執行個體。Initializes a new instance of the Point class from a Size.

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

Size,指定新 Point 的座標。A Size that specifies the coordinates for the new Point.

範例

下列程式碼範例示範如何使用Equality運算子, 以及如何PointSize或兩個整數來建立。The following code example demonstrates how to use the Equality operator and how to construct a Point from a Size or two integers. 它也會示範如何使用XY屬性。It also demonstrates how to use the X and Y properties. 這個範例是設計來與 Windows Forms 搭配使用。This example is designed to be used with Windows Forms. 將程式碼貼入包含名為Button1之按鈕的表單中, 並Button1_Click將方法與按鈕的Click事件產生關聯。Paste the code into a form that contains a button named Button1, and associate the Button1_Click method with the button's Click event.

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) Point(Int32) Point(Int32) Point(Int32)

使用由整數值指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class using coordinates specified by an integer value.

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

參數

dw
Int32 Int32 Int32 Int32

32 位元整數,指定新 Point 的座標。A 32-bit integer that specifies the coordinates for the new Point.

範例

下列程式碼範例示範如何使用PointSize.Size函式和System.Drawing.ContentAlignment列舉型別。The following code example demonstrates how to use the Point and Size.Size constructors and the System.Drawing.ContentAlignment enumeration. 若要執行此範例, 請將此程式碼貼入 Windows Form, 其中包含Label1名為的卷InitializeLabel1標, 並在表單的程式碼中呼叫方法。To run this example, paste this code into a Windows Form that contains a label named Label1, and call the InitializeLabel1 method in the form's constructor.

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 座標。The low-order 16 bits of the dw parameter specify the horizontal x-coordinate and the higher 16 bits specify the vertical y-coordinate for the new Point.

Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32)

使用指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class with the specified coordinates.

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

點的水平位置。The horizontal position of the point.

y
Int32 Int32 Int32 Int32

點的垂直位置。The vertical position of the point.

範例

下列程式碼範例示範如何使用Equality運算子, 以及如何PointSize或兩個整數來建立。The following code example demonstrates how to use the Equality operator and how to construct a Point from a Size or two integers. 它也會示範如何使用XY屬性。It also demonstrates how to use the X and Y properties. 這個範例是設計來與 Windows Forms 搭配使用。This example is designed to be used with Windows Forms. 將程式碼貼入包含名為Button1之按鈕的表單中, 並Button1_Click將方法與按鈕的Click事件產生關聯。Paste the code into a form that contains a button named Button1, and associate the Button1_Click method with the button's Click event.

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

適用於