# Graphics.FillRectangle 方法

## 重载

 FillRectangle(Brush, Rectangle) 填充 Rectangle 结构指定的矩形的内部。Fills the interior of a rectangle specified by a Rectangle structure. FillRectangle(Brush, RectangleF) 填充 RectangleF 结构指定的矩形的内部。Fills the interior of a rectangle specified by a RectangleF structure. FillRectangle(Brush, Int32, Int32, Int32, Int32) 填充由一对坐标、一个宽度和一个高度指定的矩形的内部。Fills the interior of a rectangle specified by a pair of coordinates, a width, and a height. FillRectangle(Brush, Single, Single, Single, Single) 填充由一对坐标、一个宽度和一个高度指定的矩形的内部。Fills the interior of a rectangle specified by a pair of coordinates, a width, and a height.

## FillRectangle(Brush, 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

rect
Rectangle

Rectangle 结构，它表示要填充的矩形。Rectangle structure that represents the rectangle to fill.

#### 例外

`brush``null``brush` is `null`.

### 示例

• 创建一个稳定的蓝色画笔。Creates a solid blue brush.

• 创建一个矩形。Creates a rectangle.

• 填充屏幕上的矩形区域。Fills the rectangular area on the screen.

``````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
``````

## FillRectangle(Brush, 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

rect
RectangleF

RectangleF 结构，它表示要填充的矩形。RectangleF structure that represents the rectangle to fill.

#### 例外

`brush``null``brush` is `null`.

### 示例

• 创建一个稳定的蓝色画笔。Creates a solid blue brush.

• 创建一个矩形。Creates a rectangle.

• 填充屏幕上的矩形区域。Fills the rectangular area on the screen.

``````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
``````

## 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

x
Int32

y
Int32

width
Int32

height
Int32

#### 例外

`brush``null``brush` is `null`.

### 示例

• 创建一个稳定的蓝色画笔。Creates a solid blue brush.

• 创建矩形的位置和大小。Creates the location and size of a rectangle.

• 填充屏幕上的矩形区域。Fills the rectangular area on the screen.

``````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
``````

## 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

x
Single

y
Single

width
Single

height
Single

#### 例外

`brush``null``brush` is `null`.

### 示例

• 创建一个稳定的蓝色画笔。Creates a solid blue brush.

• 创建矩形的位置和大小。Creates the location and size of a rectangle.

• 填充屏幕上的矩形区域。Fills the rectangular area on the screen.

``````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
``````