英語で読む

次の方法で共有


Point.Addition(Point, Size) Operator

定義

Point を指定の Size だけ移動します。

C#
public static System.Drawing.Point operator + (System.Drawing.Point pt, System.Drawing.Size sz);

パラメーター

pt
Point

移動する Point

sz
Size

pt の座標に追加する数の組み合わせを指定する Size

戻り値

移動された Point 構造体。

次のコード例では、これらの型に対して定義されているオーバーロードされた演算子をいくつか使用して、ポイントとサイズを作成します。 また、 クラスの使用方法 SystemPens も示します。

この例は、Windows フォームで使用するように設計されています。 という名前subtractButtonの を含むフォームをButtonCreateします。 コードをフォームに貼り付け、フォームのCreatePointsAndSizesイベント処理メソッドから メソッドをPaint呼び出し、 を としてPaintEventArgs渡しますe

C#
private void CreatePointsAndSizes(PaintEventArgs e)
{

    // Create the starting point.
    Point startPoint = new Point(subtractButton.Size);

    // Use the addition operator to get the end point.
    Point endPoint = startPoint + new Size(140, 150);

    // Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint);

    // Convert the starting point to a size and compare it to the
    // subtractButton size.  
    Size buttonSize = (Size)startPoint;
    if (buttonSize == subtractButton.Size)

        // If the sizes are equal, tell the user.
    {
        e.Graphics.DrawString("The sizes are equal.", 
            new Font(this.Font, FontStyle.Italic), 
            Brushes.Indigo, 10.0F, 65.0F);
    }
}

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1