Rectangle 結構

定義

儲存四個為一組的整數,代表矩形的位置和大小。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)
繼承
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:設定畫筆寬度和對齊 @ no__t-0。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 Forms 搭配使用所設計,而且需要 PaintEventArgs @ no__t-1,這是 @no__t 2 事件處理常式的參數。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 物件和 @no__t 1 物件。To draw rectangles, you need a Graphics object and a Pen object. @No__t 0 物件提供 DrawRectangle 方法,而 @no__t 2 物件則會儲存這一行的功能,例如色彩和寬度。The Graphics object provides the DrawRectangle method, and the Pen object stores features of the line, such as color and width. 繪製矩形的單位是由用於繪製之繪圖物件的 PageUnit 和 @no__t 1 屬性所決定。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.

若要繪製以色彩填滿的 @no__t 0,您需要一個 @no__t 的物件,以及一個衍生自 Brush 的物件,例如 SolidBrushLinearGradientBrushTo draw a Rectangle filled with color, you need a Graphics object and an object derived from Brush such as SolidBrush or LinearGradientBrush. @No__t 0 物件提供 FillRectangle 方法,而 @no__t 2 物件則提供色彩和填滿資訊。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(Int32, Int32, Int32, Int32)

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

Rectangle(Point, Size)

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

欄位

Empty

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

屬性

Bottom

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

Height

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

IsEmpty

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

Left

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

Location

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

Right

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

Size

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

Top

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

Width

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

X

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

Y

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

方法

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(Int32, Int32)

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

Contains(Point)

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

Contains(Rectangle)

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

Equals(Object)

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

Equals(Rectangle)
FromLTRB(Int32, Int32, Int32, Int32)

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

GetHashCode()

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

Inflate(Int32, Int32)

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

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.

Inflate(Size)

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

Intersect(Rectangle)

以這個 Rectangle 和指定 Rectangle 的交集,來取代其本身。Replaces this Rectangle with the intersection of itself and the specified 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.

IntersectsWith(Rectangle)

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

Offset(Int32, Int32)

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

Offset(Point)

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

Round(RectangleF)

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

ToString()

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

Truncate(RectangleF)

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

Union(Rectangle, Rectangle)

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

運算子

Equality(Rectangle, Rectangle)

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

Inequality(Rectangle, Rectangle)

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

適用於