Edit

Share via


PointF.Addition Operator

Definition

Translates the given PointF by a specified size.

Overloads

Addition(PointF, Size)

Translates a PointF by a given Size.

Addition(PointF, SizeF)

Translates the PointF by the specified SizeF.

Addition(PointF, Size)

Source:
PointF.cs
Source:
PointF.cs
Source:
PointF.cs

Translates a PointF by a given Size.

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

Parameters

pt
PointF

The PointF to translate.

sz
Size

A Size that specifies the pair of numbers to add to the coordinates of pt.

Returns

The translated PointF.

Examples

  • The following code example adds a shadow to a ListBox using the Addition operator. This example is designed to be used with a Windows Form. To run this example, paste this code into a form and call the AddShadow method when handling the form's Paint event. Make sure the form contains a ListBox named listBox1.
C#
private void AddShadow(PaintEventArgs e)
{

    // Create two SizeF objects.
    SizeF shadowSize = listBox1.Size;
    SizeF addSize = new SizeF(10.5F, 20.8F);

    // Add them together and save the result in shadowSize.
    shadowSize = shadowSize + addSize;

    // Get the location of the ListBox and convert it to a PointF.
    PointF shadowLocation = listBox1.Location;

    // Add two points to get a new location.
    shadowLocation = shadowLocation + new Size(5, 5);

    // Create a rectangleF. 
    RectangleF rectFToFill = 
        new RectangleF(shadowLocation, shadowSize);

    // Create a custom brush using a semi-transparent color, and 
    // then fill in the rectangle.
    Color customColor = Color.FromArgb(50, Color.Gray);
    SolidBrush shadowBrush = new SolidBrush(customColor);
    e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});

    // Dispose of the brush.
    shadowBrush.Dispose();
}

Applies to

.NET 9 and other versions
Product Versions
.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

Addition(PointF, SizeF)

Source:
PointF.cs
Source:
PointF.cs
Source:
PointF.cs

Translates the PointF by the specified SizeF.

C#
public static System.Drawing.PointF operator +(System.Drawing.PointF pt, System.Drawing.SizeF sz);

Parameters

pt
PointF

The PointF to translate.

sz
SizeF

The SizeF that specifies the numbers to add to the x- and y-coordinates of the PointF.

Returns

The translated PointF.

Examples

The following code example demonstrates how to use the Addition operator. To run this example, paste the following code into a Windows Form. Handle the form's Paint event and call opAdditionExample, passing e as PaintEventArgs.

C#
private void OpAdditionExample(PaintEventArgs e)
{
    PointF point1 = new PointF(120.5F, 120F);
    SizeF size1 = new SizeF(120.5F, 30.5F);
    RectangleF rect1 = new RectangleF(point1, size1);
    if (new PointF(rect1.Right, rect1.Bottom) == point1 + size1)
        e.Graphics.DrawString("They are equal", this.Font, Brushes.Black, rect1);
    else
        e.Graphics.DrawString("They are not equal", this.Font, Brushes.Red, rect1);
}

Remarks

The Addition operator adds the Width of the specified size to the x-coordinate of the PointF and the Height to the y-coordinate of the PointF.

The equivalent method for this operator is PointF.Add(PointF, SizeF)

Applies to

.NET 9 and other versions
Product Versions
.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 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