Editare

Partajați prin


Rectangle.Inflate Method

Definition

Enlarges a Rectangle structure by the specified amount.

Overloads

Inflate(Size)

Enlarges this Rectangle by the specified amount.

Inflate(Int32, Int32)

Enlarges this Rectangle by the specified amount.

Inflate(Rectangle, Int32, Int32)

Creates and returns an enlarged copy of the specified Rectangle structure. The copy is enlarged by the specified amount. The original Rectangle structure remains unmodified.

Inflate(Size)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Enlarges this Rectangle by the specified amount.

public:
 void Inflate(System::Drawing::Size size);
public void Inflate (System.Drawing.Size size);
member this.Inflate : System.Drawing.Size -> unit
Public Sub Inflate (size As Size)

Parameters

size
Size

The amount to inflate this rectangle.

Examples

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code creates a Rectangle and enlarges it by 50 units in both axes. The rectangle is drawn to screen before inflation (black) and after inflation (red).

public:
   void RectangleInflateTest2( PaintEventArgs^ e )
   {
      // Create a rectangle.
      Rectangle rect = Rectangle(100,100,50,50);

      // Draw the uninflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Black, rect );

      // Set up the inflate size.
      System::Drawing::Size inflateSize = System::Drawing::Size( 50, 50 );

      // Call Inflate.
      rect.Inflate( inflateSize );

      // Draw the inflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Red, rect );
   }
public void RectangleInflateTest2(PaintEventArgs e)
{
             
    // Create a rectangle.
    Rectangle rect = new Rectangle(100, 100, 50, 50);
             
    // Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect);
             
    // Set up the inflate size.
    Size inflateSize = new Size(50, 50);
             
    // Call Inflate.
    rect.Inflate(inflateSize);
             
    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect);
}
Public Sub RectangleInflateTest2(ByVal e As PaintEventArgs)

    ' Create a rectangle.
    Dim rect As New Rectangle(100, 100, 50, 50)

    ' Draw the uninflated rect to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect)

    ' Set up the inflate size.
    Dim inflateSize As New Size(50, 50)

    ' Call Inflate.
    rect.Inflate(inflateSize)

    ' Draw the inflated rect to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect)
End Sub

Remarks

This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is enlarged by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center.

Applies to

Inflate(Int32, Int32)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Enlarges this Rectangle by the specified amount.

public:
 void Inflate(int width, int height);
public void Inflate (int width, int height);
member this.Inflate : int * int -> unit
Public Sub Inflate (width As Integer, height As Integer)

Parameters

width
Int32

The amount to inflate this Rectangle horizontally.

height
Int32

The amount to inflate this Rectangle vertically.

Examples

The following example creates a Rectangle structure and enlarges it by 100 units in the x-axis direction:

public:
   void RectangleInflateTest3( PaintEventArgs^ e )
   {
      // Create a rectangle.
      Rectangle rect = Rectangle(100,100,50,50);

      // Draw the uninflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Black, rect );

      // Call Inflate.
      rect.Inflate( 50, 50 );

      // Draw the inflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Red, rect );
   }
public void RectangleInflateTest3(PaintEventArgs e)
{
             
    // Create a rectangle.
    Rectangle rect = new Rectangle(100, 100, 50, 50);
             
    // Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect);
             
    // Call Inflate.
    rect.Inflate(50, 50);
             
    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect);
}
Public Sub RectangleInflateTest3(ByVal e As PaintEventArgs)

    ' Create a rectangle.
    Dim rect As New Rectangle(100, 100, 50, 50)

    ' Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect)

    ' Call Inflate.
    rect.Inflate(50, 50)

    ' Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect)
End Sub

Remarks

This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is enlarged by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center.

If either x or y is negative, the Rectangle structure is deflated in the corresponding direction.

Applies to

Inflate(Rectangle, Int32, Int32)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Creates and returns an enlarged copy of the specified Rectangle structure. The copy is enlarged by the specified amount. The original Rectangle structure remains unmodified.

public:
 static System::Drawing::Rectangle Inflate(System::Drawing::Rectangle rect, int x, int y);
public static System.Drawing.Rectangle Inflate (System.Drawing.Rectangle rect, int x, int y);
static member Inflate : System.Drawing.Rectangle * int * int -> System.Drawing.Rectangle
Public Shared Function Inflate (rect As Rectangle, x As Integer, y As Integer) As Rectangle

Parameters

rect
Rectangle

The Rectangle with which to start. This rectangle is not modified.

x
Int32

The amount to inflate this Rectangle horizontally.

y
Int32

The amount to inflate this Rectangle vertically.

Returns

The enlarged Rectangle.

Examples

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code creates a Rectangle and enlarges it by 50 units in both axes. Notice that the resulting rectangle (red) is 150 units in both axes.

public:
   void RectangleInflateTest( PaintEventArgs^ e )
   {
      // Create a rectangle.
      Rectangle rect = Rectangle(100,100,50,50);

      // Draw the uninflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Black, rect );

      // Call Inflate.
      Rectangle rect2 = Rectangle::Inflate( rect, 50, 50 );

      // Draw the inflated rectangle to screen.
      e->Graphics->DrawRectangle( Pens::Red, rect2 );
   }
public void RectangleInflateTest(PaintEventArgs e)
{
             
    // Create a rectangle.
    Rectangle rect = new Rectangle(100, 100, 50, 50);
             
    // Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect);
             
    // Call Inflate.
    Rectangle rect2 = Rectangle.Inflate(rect, 50, 50);
             
    // Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect2);
}
Public Sub RectangleInflateTest(ByVal e As PaintEventArgs)

    ' Create a rectangle.
    Dim rect As New Rectangle(100, 100, 50, 50)

    ' Draw the uninflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Black, rect)

    ' Call Inflate.
    Dim rect2 As Rectangle = Rectangle.Inflate(rect, 50, 50)

    ' Draw the inflated rectangle to screen.
    e.Graphics.DrawRectangle(Pens.Red, rect2)
End Sub

Remarks

This method makes a copy of rect, enlarges the copy, and then returns the enlarged copy. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is enlarged by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center.

Applies to