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 窗体,并且它需要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对象和一个对象派生自BrushSolidBrushLinearGradientBrushTo 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)

将此 Rectangle 放大指定量。Enlarges this Rectangle by the specified amount.

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

将此 Rectangle 放大指定量。Enlarges 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 舍入到最近的整数值,将指定的 Rectangle 转换为 RectangleFConverts 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.

适用于