Graphics.DrawRectangle 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
繪製座標組、寬度和高度所指定的矩形。
多載
DrawRectangle(Pen, Int32, Int32, Int32, Int32) |
繪製座標組、寬度和高度所指定的矩形。 |
DrawRectangle(Pen, Single, Single, Single, Single) |
繪製座標組、寬度和高度所指定的矩形。 |
DrawRectangle(Pen, RectangleF) |
繪製指定矩形的外框。 |
DrawRectangle(Pen, Rectangle) |
繪製由 Rectangle 結構指定的矩形。 |
DrawRectangle(Pen, Int32, Int32, Int32, Int32)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
繪製座標組、寬度和高度所指定的矩形。
public:
void DrawRectangle(System::Drawing::Pen ^ pen, int x, int y, int width, int height);
public void DrawRectangle (System.Drawing.Pen pen, int x, int y, int width, int height);
member this.DrawRectangle : System.Drawing.Pen * int * int * int * int -> unit
Public Sub DrawRectangle (pen As Pen, x As Integer, y As Integer, width As Integer, height As Integer)
參數
- x
- Int32
要繪製之矩形左上角的 X 座標。
- y
- Int32
要繪製之矩形左上角的 Y 座標。
- width
- Int32
要繪製之矩形的寬度。
- height
- Int32
要繪製之矩形的高度。
例外狀況
pen
null
。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立黑色畫筆。
建立矩形的位置和大小。
將矩形繪製到畫面。
public:
void DrawRectangleInt( PaintEventArgs^ e )
{
// Create pen.
Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
// Create location and size of rectangle.
int x = 0;
int y = 0;
int width = 200;
int height = 200;
// Draw rectangle to screen.
e->Graphics->DrawRectangle( blackPen, x, y, width, height );
}
public void DrawRectangleInt(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create location and size of rectangle.
int x = 0;
int y = 0;
int width = 200;
int height = 200;
// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height);
}
Public Sub DrawRectangleInt(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' 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
' Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub
備註
如需如何繪製 RectangleF的詳細資訊,請參閱 DrawRectangles(Pen, RectangleF[])。
適用於
DrawRectangle(Pen, Single, Single, Single, Single)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
繪製座標組、寬度和高度所指定的矩形。
public:
void DrawRectangle(System::Drawing::Pen ^ pen, float x, float y, float width, float height);
public void DrawRectangle (System.Drawing.Pen pen, float x, float y, float width, float height);
member this.DrawRectangle : System.Drawing.Pen * single * single * single * single -> unit
Public Sub DrawRectangle (pen As Pen, x As Single, y As Single, width As Single, height As Single)
參數
- x
- Single
要繪製之矩形左上角的 X 座標。
- y
- Single
要繪製之矩形左上角的 Y 座標。
- width
- Single
要繪製之矩形的寬度。
- height
- Single
要繪製之矩形的高度。
例外狀況
pen
null
。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立黑色畫筆。
建立矩形的位置和大小。
將矩形繪製到畫面。
public:
void DrawRectangleFloat( PaintEventArgs^ e )
{
// Create pen.
Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
// Create location and size of rectangle.
float x = 0.0F;
float y = 0.0F;
float width = 200.0F;
float height = 200.0F;
// Draw rectangle to screen.
e->Graphics->DrawRectangle( blackPen, x, y, width, height );
}
public void DrawRectangleFloat(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create location and size of rectangle.
float x = 0.0F;
float y = 0.0F;
float width = 200.0F;
float height = 200.0F;
// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height);
}
Public Sub DrawRectangleFloat(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' 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
' Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, x, y, width, height)
End Sub
備註
如需如何繪製 RectangleF的詳細資訊,請參閱 DrawRectangles(Pen, RectangleF[])。
適用於
DrawRectangle(Pen, RectangleF)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
繪製指定矩形的外框。
public:
void DrawRectangle(System::Drawing::Pen ^ pen, System::Drawing::RectangleF rect);
public void DrawRectangle (System.Drawing.Pen pen, System.Drawing.RectangleF rect);
member this.DrawRectangle : System.Drawing.Pen * System.Drawing.RectangleF -> unit
Public Sub DrawRectangle (pen As Pen, rect As RectangleF)
參數
- pen
- Pen
決定矩形色彩、寬度和樣式的畫筆。
- rect
- RectangleF
要繪製的矩形。
適用於
DrawRectangle(Pen, Rectangle)
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
繪製由 Rectangle 結構指定的矩形。
public:
void DrawRectangle(System::Drawing::Pen ^ pen, System::Drawing::Rectangle rect);
public void DrawRectangle (System.Drawing.Pen pen, System.Drawing.Rectangle rect);
member this.DrawRectangle : System.Drawing.Pen * System.Drawing.Rectangle -> unit
Public Sub DrawRectangle (pen As Pen, rect As Rectangle)
參數
例外狀況
pen
null
。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立黑色畫筆。
建立矩形。
將矩形繪製到畫面。
public:
void DrawRectangleRectangle( PaintEventArgs^ e )
{
// Create pen.
Pen^ blackPen = gcnew Pen( Color::Black,3.0f );
// Create rectangle.
Rectangle rect = Rectangle(0,0,200,200);
// Draw rectangle to screen.
e->Graphics->DrawRectangle( blackPen, rect );
}
public void DrawRectangleRectangle(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);
// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect);
}
Public Sub DrawRectangleRectangle(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create rectangle.
Dim rect As New Rectangle(0, 0, 200, 200)
' Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect)
End Sub
備註
如需如何繪製 RectangleF的詳細資訊,請參閱 DrawRectangles(Pen, RectangleF[])。