Graphics.FillRectangle 方法

定義

填充由一對座標、寬度和高度指定的矩形內部。

多載

名稱 Description
FillRectangle(Brush, Rectangle)

填充由 Rectangle 結構指定的矩形內部。

FillRectangle(Brush, RectangleF)

填充由 RectangleF 結構指定的矩形內部。

FillRectangle(Brush, Int32, Int32, Int32, Int32)

填充由一對座標、寬度和高度指定的矩形內部。

FillRectangle(Brush, Single, Single, Single, Single)

填充由一對座標、寬度和高度指定的矩形內部。

FillRectangle(Brush, Rectangle)

填充由 Rectangle 結構指定的矩形內部。

public:
 void FillRectangle(System::Drawing::Brush ^ brush, System::Drawing::Rectangle rect);
public void FillRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect);
member this.FillRectangle : System.Drawing.Brush * System.Drawing.Rectangle -> unit
Public Sub FillRectangle (brush As Brush, rect As Rectangle)

參數

brush
Brush

Brush 這決定了填料的特性。

rect
Rectangle

Rectangle 代表要填滿矩形的結構。

例外狀況

brushnull

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 程式代碼會執行下列動作:

  • 這樣會產生純藍色的刷子。

  • 形成一個矩形。

  • 填滿螢幕上的長方形區域。

public:
   void FillRectangleRectangle( PaintEventArgs^ e )
   {
      // Create solid brush.
      SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

      // Create rectangle.
      Rectangle rect = Rectangle(0,0,200,200);

      // Fill rectangle to screen.
      e->Graphics->FillRectangle( blueBrush, rect );
   }
private void FillRectangleRectangle(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create rectangle.
    Rectangle rect = new Rectangle(0, 0, 200, 200);

    // Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, rect);
}
Private Sub FillRectangleRectangle(ByVal e As PaintEventArgs)

    ' Create solid brush.
    Dim blueBrush As New SolidBrush(Color.Blue)

    ' Create rectangle.
    Dim rect As New Rectangle(0, 0, 200, 200)

    ' Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, rect)
End Sub

備註

此方法填充由 rect 參數定義的矩形內部,包括指定的左上角,並至計算出的上下邊緣。

適用於

FillRectangle(Brush, RectangleF)

填充由 RectangleF 結構指定的矩形內部。

public:
 void FillRectangle(System::Drawing::Brush ^ brush, System::Drawing::RectangleF rect);
public void FillRectangle(System.Drawing.Brush brush, System.Drawing.RectangleF rect);
member this.FillRectangle : System.Drawing.Brush * System.Drawing.RectangleF -> unit
Public Sub FillRectangle (brush As Brush, rect As RectangleF)

參數

brush
Brush

Brush 這決定了填料的特性。

rect
RectangleF

RectangleF 代表要填滿矩形的結構。

例外狀況

brushnull

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 程式代碼會執行下列動作:

  • 這樣會產生純藍色的刷子。

  • 形成一個矩形。

  • 填滿螢幕上的長方形區域。

public:
   void FillRectangleRectangleF( PaintEventArgs^ e )
   {
      // Create solid brush.
      SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

      // Create rectangle.
      RectangleF rect = RectangleF(0.0F,0.0F,200.0F,200.0F);

      // Fill rectangle to screen.
      e->Graphics->FillRectangle( blueBrush, rect );
   }
private void FillRectangleRectangleF(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create rectangle.
    RectangleF rect = new RectangleF(0.0F, 0.0F, 200.0F, 200.0F);

    // Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, rect);
}
Private Sub FillRectangleRectangleF(ByVal e As PaintEventArgs)

    ' Create solid brush.
    Dim blueBrush As New SolidBrush(Color.Blue)

    ' Create rectangle.
    Dim rect As New RectangleF(0.0F, 0.0F, 200.0F, 200.0F)

    ' Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, rect)
End Sub

備註

此方法填充由 rect 參數定義的矩形內部,包括指定的左上角,並至計算出的上下邊緣。

適用於

FillRectangle(Brush, Int32, Int32, Int32, Int32)

填充由一對座標、寬度和高度指定的矩形內部。

public:
 void FillRectangle(System::Drawing::Brush ^ brush, int x, int y, int width, int height);
public void FillRectangle(System.Drawing.Brush brush, int x, int y, int width, int height);
member this.FillRectangle : System.Drawing.Brush * int * int * int * int -> unit
Public Sub FillRectangle (brush As Brush, x As Integer, y As Integer, width As Integer, height As Integer)

參數

brush
Brush

Brush 這決定了填料的特性。

x
Int32

填滿矩形左上角的 x 座標。

y
Int32

填滿矩形左上角的 y 座標。

width
Int32

要填滿矩形的寬度。

height
Int32

要填滿矩形的高度。

例外狀況

brushnull

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 程式代碼會執行下列動作:

  • 這樣會產生純藍色的刷子。

  • 建立矩形的位置與大小。

  • 填滿螢幕上的長方形區域。

public:
   void FillRectangleInt( PaintEventArgs^ e )
   {
      // Create solid brush.
      SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

      // Create location and size of rectangle.
      int x = 0;
      int y = 0;
      int width = 200;
      int height = 200;

      // Fill rectangle to screen.
      e->Graphics->FillRectangle( blueBrush, x, y, width, height );
   }
private void FillRectangleInt(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create location and size of rectangle.
    int x = 0;
    int y = 0;
    int width = 200;
    int height = 200;

    // Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, x, y, width, height);
}
Private Sub FillRectangleInt(ByVal e As PaintEventArgs)

    ' Create solid brush.
    Dim blueBrush As New SolidBrush(Color.Blue)

    ' Create location and size of rectangle.
    Dim x As Integer = 0
    Dim y As Integer = 0
    Dim width As Integer = 200
    Dim height As Integer = 200

    ' Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, x, y, width, height)
End Sub

備註

此方法填充由xy 、 、 widthheight 及參數定義的矩形內部,包括指定的左上角及計算出的下邊與底部邊緣。

適用於

FillRectangle(Brush, Single, Single, Single, Single)

填充由一對座標、寬度和高度指定的矩形內部。

public:
 void FillRectangle(System::Drawing::Brush ^ brush, float x, float y, float width, float height);
public void FillRectangle(System.Drawing.Brush brush, float x, float y, float width, float height);
member this.FillRectangle : System.Drawing.Brush * single * single * single * single -> unit
Public Sub FillRectangle (brush As Brush, x As Single, y As Single, width As Single, height As Single)

參數

brush
Brush

Brush 這決定了填料的特性。

x
Single

填滿矩形左上角的 x 座標。

y
Single

填滿矩形左上角的 y 座標。

width
Single

要填滿矩形的寬度。

height
Single

要填滿矩形的高度。

例外狀況

brushnull

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 程式代碼會執行下列動作:

  • 這樣會產生純藍色的刷子。

  • 建立矩形的位置與大小。

  • 填滿螢幕上的長方形區域。

public:
   void FillRectangleFloat( PaintEventArgs^ e )
   {
      // Create solid brush.
      SolidBrush^ blueBrush = gcnew SolidBrush( Color::Blue );

      // Create location and size of rectangle.
      float x = 0.0F;
      float y = 0.0F;
      float width = 200.0F;
      float height = 200.0F;

      // Fill rectangle to screen.
      e->Graphics->FillRectangle( blueBrush, x, y, width, height );
   }
private void FillRectangleFloat(PaintEventArgs e)
{

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create location and size of rectangle.
    float x = 0.0F;
    float y = 0.0F;
    float width = 200.0F;
    float height = 200.0F;

    // Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, x, y, width, height);
}
Private Sub FillRectangleFloat(ByVal e As PaintEventArgs)

    ' Create solid brush.
    Dim blueBrush As New SolidBrush(Color.Blue)

    ' Create location and size of rectangle.
    Dim x As Single = 0.0F
    Dim y As Single = 0.0F
    Dim width As Single = 200.0F
    Dim height As Single = 200.0F

    ' Fill rectangle to screen.
    e.Graphics.FillRectangle(blueBrush, x, y, width, height)
End Sub

備註

此方法填充由 xywidthheight 及參數定義的矩形內部,包括指定的左上角,直到計算出的上下邊緣。

適用於