Point.X 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定這個 Point 的 X 座標。
public:
property int X { int get(); void set(int value); };
public int X { get; set; }
member this.X : int with get, set
Public Property X As Integer
屬性值
這個 Point 的 X 座標。
範例
下列程式代碼範例示範如何使用 Equality 運算子,以及如何從 或兩個PointSize整數建構 。 它也會示範如何使用 X 和 Y 屬性。 此範例的設計目的是要與 Windows Forms 搭配使用。 將程式代碼貼到包含名為Button1
的按鈕的表單中,並將方法與按鈕Click的事件產生關聯Button1_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