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. 如需畫筆對齊的詳細資訊, 請參閱如何:設定畫筆寬度和對齊方式。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而且它需要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)

備註

矩形是由Width Location屬性所表示的Height、和左上角所定義。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. 物件會提供方法, 而Pen物件會儲存線條的特徵, 例如色彩和寬度。 DrawRectangle GraphicsThe 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需要物件和衍生自BrushSolidBrush物件, 例如或LinearGradientBrushTo draw a Rectangle filled with color, you need a Graphics object and an object derived from Brush such as SolidBrush or LinearGradientBrush. 物件會提供方法, 而Brush物件則提供色彩和填滿資訊。 FillRectangle GraphicsThe 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.

適用於