Rectangle Rectangle Rectangle Rectangle Struct

定義

儲存四個為一組的整數,代表矩形的位置和大小。Stores a set of four integers that represent the location and size of a rectangle

public value class Rectangle : IEquatable<System::Drawing::Rectangle>
[System.ComponentModel.TypeConverter(typeof(System.Drawing.RectangleConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Rectangle : IEquatable<System.Drawing.Rectangle>
type Rectangle = struct
Public Structure Rectangle
Implements IEquatable(Of Rectangle)
繼承
屬性
實作

範例

下列範例會繪製在其左上角的矩形 (10,10)。The following example draws a rectangle with its upper-left corner at (10, 10). 矩形的寬度為 100 且高度為 50。The rectangle has a width of 100 and a height of 50. 第二個引數傳遞至Pen建構函式表示畫筆寬度為 5 像素。The second argument passed to the Pen constructor indicates that the pen width is 5 pixels.

繪製矩形時,畫筆會集中在矩形的界限中。When the rectangle is drawn, the pen is centered on the rectangle's boundary. 矩形邊的畫筆寬度為 5,因為會繪製的 5 個像素 1 個像素寬、 這類會繪製在內部,繪製界限,2 個像素和 2 個像素會繪製在外部。Because the pen width is 5, the sides of the rectangle are drawn 5 pixels wide, such that 1 pixel is drawn on the boundary itself, 2 pixels are drawn on the inside, and 2 pixels are drawn on the outside. 如需畫筆對齊方式的詳細資訊,請參閱How to:設定畫筆寬度和對齊For more details on pen alignment, see How to: Set Pen Width and Alignment.

下圖顯示產生的矩形。The following illustration shows the resulting rectangle. 虛線顯示,其中會有已繪製矩形如果畫筆寬度有一個像素。The dotted lines show where the rectangle would have been drawn if the pen width had been one pixel. 矩形左上角的放大的檢視顯示黑色粗線會置於這些點線。The enlarged view of the upper-left corner of the rectangle shows that the thick black lines are centered on those dotted lines.

畫筆Pens

此範例專為搭配 Windows Form 使用,而且需要PaintEventArgs e,這是參數的Paint事件處理常式。The example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler.

Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 5);
e.Graphics.DrawRectangle(blackPen, 10, 10, 100, 50);
Dim blackPen As New Pen(Color.FromArgb(255, 0, 0, 0), 5)
e.Graphics.DrawRectangle(blackPen, 10, 10, 100, 50)

備註

所定義的矩形及其WidthHeight,以及所代表的左上角Location屬性。A rectangle is defined by its Width, Height, and upper-left corner represented by the Location property.

若要繪製矩形,您需要Graphics物件和Pen物件。To draw rectangles, you need a Graphics object and a Pen object. Graphics物件會提供DrawRectangle方法,而Pen物件會儲存的行,例如色彩和寬度的功能。The Graphics object provides the DrawRectangle method, and the Pen object stores features of the line, such as color and width. 在繪製矩形的單位由PageUnitPageScale用於繪製物件的圖形的屬性。The units the rectangle is drawn in is determined by the PageUnit and PageScale properties of the graphics object used for drawing. 預設單位為像素。The default unit is pixels.

若要繪製Rectangle填滿色彩,您需要Graphics物件和物件衍生自Brush這類SolidBrushLinearGradientBrushTo draw a Rectangle filled with color, you need a Graphics object and an object derived from Brush such as SolidBrush or LinearGradientBrush. Graphics物件會提供FillRectangle方法和Brush物件提供的色彩和填滿的資訊。The Graphics object provides the FillRectangle method and the Brush object provides the color and fill information.

若為更進階的形狀,使用Region物件。For more advanced shapes, use a Region object.

建構函式

Rectangle(Point, Size) Rectangle(Point, Size) Rectangle(Point, Size) Rectangle(Point, Size)

使用指定的位置和大小來初始化 Rectangle 類別的新執行個體。Initializes a new instance of the Rectangle class with the specified location and size.

Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32)

使用指定的位置和大小來初始化 Rectangle 類別的新執行個體。Initializes a new instance of the Rectangle class with the specified location and size.

欄位

Empty Empty Empty Empty

代表其屬性未初始化的 Rectangle 結構。Represents a Rectangle structure with its properties left uninitialized.

屬性

Bottom Bottom Bottom Bottom

取得 Y 座標,其為這個 Rectangle 結構之 YHeight 屬性值的總和。Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure.

Height Height Height Height

取得或設定這個 Rectangle 結構的高度。Gets or sets the height of this Rectangle structure.

IsEmpty IsEmpty IsEmpty IsEmpty

測試這個 Rectangle 的所有數值屬性是否具有零值。Tests whether all numeric properties of this Rectangle have values of zero.

Left Left Left Left

取得這個 Rectangle 結構左邊緣的 X 座標。Gets the x-coordinate of the left edge of this Rectangle structure.

Location Location Location Location

取得或設定這個 Rectangle 結構的左上角座標。Gets or sets the coordinates of the upper-left corner of this Rectangle structure.

Right Right Right Right

取得 X 座標,其為這個 Rectangle 結構之 XWidth 屬性值的總和。Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure.

Size Size Size Size

取得或設定這個 Rectangle 的大小。Gets or sets the size of this Rectangle.

Top Top Top Top

取得這個 Rectangle 結構上邊緣的 Y 座標。Gets the y-coordinate of the top edge of this Rectangle structure.

Width Width Width Width

取得或設定這個 Rectangle 結構的寬度。Gets or sets the width of this Rectangle structure.

X X X X

取得或設定這個 Rectangle 結構的左上角 X 座標。Gets or sets the x-coordinate of the upper-left corner of this Rectangle structure.

Y Y Y Y

取得或設定這個 Rectangle 結構的左上角 Y 座標。Gets or sets the y-coordinate of the upper-left corner of this Rectangle structure.

方法

Ceiling(RectangleF) Ceiling(RectangleF) Ceiling(RectangleF) Ceiling(RectangleF)

藉由將 RectangleF 值捨入為下一個較大的整數值,來將指定的 RectangleF 結構轉換為 Rectangle 結構。Converts the specified RectangleF structure to a Rectangle structure by rounding the RectangleF values to the next higher integer values.

Contains(Point) Contains(Point) Contains(Point) Contains(Point)

判斷指定的點是否包含在這個 Rectangle 結構內。Determines if the specified point is contained within this Rectangle structure.

Contains(Rectangle) Contains(Rectangle) Contains(Rectangle) Contains(Rectangle)

判斷由 rect 表示的矩形區域是否完全包含在這個 Rectangle 結構中。Determines if the rectangular region represented by rect is entirely contained within this Rectangle structure.

Contains(Int32, Int32) Contains(Int32, Int32) Contains(Int32, Int32) Contains(Int32, Int32)

判斷指定的點是否包含在這個 Rectangle 結構內。Determines if the specified point is contained within this Rectangle structure.

Equals(Rectangle) Equals(Rectangle) Equals(Rectangle) Equals(Rectangle)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

測試 obj 是否為具有和這個 Rectangle 結構相同位置和大小的 Rectangle 結構。Tests whether obj is a Rectangle structure with the same location and size of this Rectangle structure.

FromLTRB(Int32, Int32, Int32, Int32) FromLTRB(Int32, Int32, Int32, Int32) FromLTRB(Int32, Int32, Int32, Int32) FromLTRB(Int32, Int32, Int32, Int32)

使用指定的邊緣位置來建立 Rectangle 結構。Creates a Rectangle structure with the specified edge locations.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個 Rectangle 結構的雜湊程式碼。Returns the hash code for this Rectangle structure. 如需使用雜湊程式碼的相關資訊,請參閱 GetHashCode()For information about the use of hash codes, see GetHashCode() .

Inflate(Size) Inflate(Size) Inflate(Size) Inflate(Size)

根據指定的數量來放大這個 RectangleEnlarges this Rectangle by the specified amount.

Inflate(Int32, Int32) Inflate(Int32, Int32) Inflate(Int32, Int32) Inflate(Int32, Int32)

根據指定的數量來放大這個 RectangleEnlarges this Rectangle by the specified amount.

Inflate(Rectangle, Int32, Int32) Inflate(Rectangle, Int32, Int32) Inflate(Rectangle, Int32, Int32) Inflate(Rectangle, Int32, Int32)

建立並傳回指定之 Rectangle 結構的放大複本。Creates and returns an enlarged copy of the specified Rectangle structure. 複本會以指定的數量來放大。The copy is enlarged by the specified amount. 原始的 Rectangle 結構則維持不修改。The original Rectangle structure remains unmodified.

Intersect(Rectangle, Rectangle) Intersect(Rectangle, Rectangle) Intersect(Rectangle, Rectangle) Intersect(Rectangle, Rectangle)

傳回第三個 Rectangle 結構,該結構代表其他兩個 Rectangle 結構的交集。Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. 如果沒有交集,則會傳回空的 RectangleIf there is no intersection, an empty Rectangle is returned.

Intersect(Rectangle) Intersect(Rectangle) Intersect(Rectangle) Intersect(Rectangle)

以這個 Rectangle 和指定 Rectangle 的交集,來取代其本身。Replaces this Rectangle with the intersection of itself and the specified Rectangle.

IntersectsWith(Rectangle) IntersectsWith(Rectangle) IntersectsWith(Rectangle) IntersectsWith(Rectangle)

判斷這個矩形是否與 rect 交集。Determines if this rectangle intersects with rect.

Offset(Point) Offset(Point) Offset(Point) Offset(Point)

以所指定數量來調整這個矩形的位置。Adjusts the location of this rectangle by the specified amount.

Offset(Int32, Int32) Offset(Int32, Int32) Offset(Int32, Int32) Offset(Int32, Int32)

以所指定數量來調整這個矩形的位置。Adjusts the location of this rectangle by the specified amount.

Round(RectangleF) Round(RectangleF) Round(RectangleF) Round(RectangleF)

藉由將 RectangleF 值捨入為最接近的整數值,來將指定的 RectangleF 轉換為 RectangleConverts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.

ToString() ToString() ToString() ToString()

將這個 Rectangle 之屬性轉換為人們可讀取的字串。Converts the attributes of this Rectangle to a human-readable string.

Truncate(RectangleF) Truncate(RectangleF) Truncate(RectangleF) Truncate(RectangleF)

藉由截斷 RectangleF 值,來將指定的 RectangleF 轉換為 RectangleConverts the specified RectangleF to a Rectangle by truncating the RectangleF values.

Union(Rectangle, Rectangle) Union(Rectangle, Rectangle) Union(Rectangle, Rectangle) Union(Rectangle, Rectangle)

取得 Rectangle 結構,該結構包含兩個 Rectangle 結構的聯集。Gets a Rectangle structure that contains the union of two Rectangle structures.

運算子

Equality(Rectangle, Rectangle) Equality(Rectangle, Rectangle) Equality(Rectangle, Rectangle) Equality(Rectangle, Rectangle)

測試兩個 Rectangle 結構是否具有相等的位置和大小。Tests whether two Rectangle structures have equal location and size.

Inequality(Rectangle, Rectangle) Inequality(Rectangle, Rectangle) Inequality(Rectangle, Rectangle) Inequality(Rectangle, Rectangle)

測試兩個 Rectangle 結構的位置或大小是否不同。Tests whether two Rectangle structures differ in location or size.

適用於