Rectangle.Inflate 方法

定义

按指定量放大 Rectangle 结构。

重载

Inflate(Size)

将此 Rectangle 放大指定金额。

Inflate(Int32, Int32)

将此 Rectangle 放大指定金额。

Inflate(Rectangle, Int32, Int32)

创建并返回指定 Rectangle 结构的放大副本。 副本按指定的金额放大。 原始 Rectangle 结构保持不变。

Inflate(Size)

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

将此 Rectangle 放大指定金额。

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)

参数

size
Size

放大此矩形的量。

示例

下面的示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码将创建一个 Rectangle,并在两个轴中将其放大 50 个单位。 矩形在通货膨胀(黑色)和通货膨胀后(红色)之前绘制为屏幕。

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

注解

此方法放大此矩形,而不是该矩形的副本。 矩形沿轴向两个方向放大。 例如,如果在 x 轴中放大 50 到 50 个矩形,则生成的矩形长 150 单位(原始 50,负方向为 50,加方向为 50),并保留矩形几何中心 50。

适用于

Inflate(Int32, Int32)

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

将此 Rectangle 放大指定金额。

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)

参数

width
Int32

水平膨胀此 Rectangle 量。

height
Int32

垂直膨胀此 Rectangle 量。

示例

以下示例创建一个 Rectangle 结构,并在 x 轴方向将其放大 100 个单位:

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

注解

此方法放大此矩形,而不是该矩形的副本。 矩形沿轴向两个方向放大。 例如,如果在 x 轴中放大 50 到 50 个矩形,则生成的矩形长 150 单位(原始 50,负方向为 50,加方向为 50),并保留矩形几何中心 50。

如果 xy 为负值,则 Rectangle 结构将按相应的方向平展。

适用于

Inflate(Rectangle, Int32, Int32)

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

创建并返回指定 Rectangle 结构的放大副本。 副本按指定的金额放大。 原始 Rectangle 结构保持不变。

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

参数

rect
Rectangle

要从其开始的 Rectangle。 此矩形未修改。

x
Int32

水平膨胀此 Rectangle 量。

y
Int32

垂直膨胀此 Rectangle 量。

返回

放大 Rectangle

示例

下面的示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码将创建一个 Rectangle,并在两个轴中将其放大 50 个单位。 请注意,生成的矩形(红色)是两个轴中的 150 个单位。

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

注解

此方法创建 rect副本,放大副本,然后返回放大的副本。 矩形沿轴向两个方向放大。 例如,如果在 x 轴中放大 50 到 50 个矩形,则生成的矩形长 150 单位(原始 50,负方向为 50,加方向为 50),并保留矩形几何中心 50。

适用于