Pen 类
定义
定义用于绘制直线和曲线的对象。Defines an object used to draw lines and curves. 此类不能被继承。This class cannot be inherited.
public ref class Pen sealed : MarshalByRefObject, ICloneable, IDisposable
public sealed class Pen : MarshalByRefObject, ICloneable, IDisposable
type Pen = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
Public NotInheritable Class Pen
Inherits MarshalByRefObject
Implements ICloneable, IDisposable
- 继承
- 实现
示例
下面的代码示例演示如何 Pen 使用和在 Brush 上设置属性的效果来构造 LineJoin Pen 。The following code example demonstrates constructing a Pen with a Brush and the effects of setting the LineJoin property on a Pen.
此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 将代码粘贴到窗体中,并 ShowLineJoin 在处理窗体事件时调用方法,并将 Paint e 作为传递 PaintEventArgs 。Paste the code into a form and call the ShowLineJoin method when handling the form's Paint event, passing e as PaintEventArgs.
private:
void ShowLineJoin( PaintEventArgs^ e )
{
// Create a new pen.
Pen^ skyBluePen = gcnew Pen( Brushes::DeepSkyBlue );
// Set the pen's width.
skyBluePen->Width = 8.0F;
// Set the LineJoin property.
skyBluePen->LineJoin = System::Drawing::Drawing2D::LineJoin::Bevel;
// Draw a rectangle.
e->Graphics->DrawRectangle( skyBluePen, Rectangle(40,40,150,200) );
//Dispose of the pen.
delete skyBluePen;
}
private void ShowLineJoin(PaintEventArgs e)
{
// Create a new pen.
Pen skyBluePen = new Pen(Brushes.DeepSkyBlue);
// Set the pen's width.
skyBluePen.Width = 8.0F;
// Set the LineJoin property.
skyBluePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
// Draw a rectangle.
e.Graphics.DrawRectangle(skyBluePen,
new Rectangle(40, 40, 150, 200));
//Dispose of the pen.
skyBluePen.Dispose();
}
Private Sub ShowLineJoin(ByVal e As PaintEventArgs)
' Create a new pen.
Dim skyBluePen As New Pen(Brushes.DeepSkyBlue)
' Set the pen's width.
skyBluePen.Width = 8.0F
' Set the LineJoin property.
skyBluePen.LineJoin = Drawing2D.LineJoin.Bevel
' Draw a rectangle.
e.Graphics.DrawRectangle(skyBluePen, _
New Rectangle(40, 40, 150, 200))
'Dispose of the pen.
skyBluePen.Dispose()
End Sub
注解
Pen绘制指定宽度和样式的线条。A Pen draws a line of specified width and style. 使用 DashStyle 属性可绘制多种虚线。Use the DashStyle property to draw several varieties of dashed lines. 绘制的线条 Pen 可以使用各种填充样式(包括纯色和纹理)进行填充。The line drawn by a Pen can be filled in a variety of fill styles, including solid colors and textures. 填充样式取决于用作填充对象的画笔或纹理。The fill style depends on brush or texture that is used as the fill object.
构造函数
| Pen(Brush) |
使用指定的 Pen 初始化 Brush 类的新实例。Initializes a new instance of the Pen class with the specified Brush. |
| Pen(Brush, Single) |
使用指定的 Pen 和 Brush 初始化 Width 类的新实例。Initializes a new instance of the Pen class with the specified Brush and Width. |
| Pen(Color) |
用指定颜色初始化 Pen 类的新实例。Initializes a new instance of the Pen class with the specified color. |
| Pen(Color, Single) |
用指定的 Pen 和 Color 属性初始化 Width 类的新实例。Initializes a new instance of the Pen class with the specified Color and Width properties. |
属性
| Alignment | |
| Brush |
获取或设置 Brush,用于确定此 Pen 的特性。Gets or sets the Brush that determines attributes of this Pen. |
| Color | |
| CompoundArray |
获取或设置用于指定复合钢笔的值数组。Gets or sets an array of values that specifies a compound pen. 复合钢笔绘制由平行直线和空白区域组成的复合直线。A compound pen draws a compound line made up of parallel lines and spaces. |
| CustomEndCap |
获取或设置要在通过此 Pen 绘制的直线终点使用的自定义线帽。Gets or sets a custom cap to use at the end of lines drawn with this Pen. |
| CustomStartCap |
获取或设置要在通过此 Pen 绘制的直线起点使用的自定义线帽。Gets or sets a custom cap to use at the beginning of lines drawn with this Pen. |
| DashCap |
获取或设置用在短划线终点的线帽样式,这些短划线构成通过此 Pen 绘制的虚线。Gets or sets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen. |
| DashOffset |
获取或设置直线的起点到短划线图案起始处的距离。Gets or sets the distance from the start of a line to the beginning of a dash pattern. |
| DashPattern |
获取或设置自定义的短划线和空白区域的数组。Gets or sets an array of custom dashes and spaces. |
| DashStyle |
获取或设置用于通过此 Pen 绘制的虚线的样式。Gets or sets the style used for dashed lines drawn with this Pen. |
| EndCap |
获取或设置要在通过此 Pen 绘制的直线终点使用的线帽样式。Gets or sets the cap style used at the end of lines drawn with this Pen. |
| LineJoin |
获取或设置通过此 Pen 绘制的两条连续直线的端点的联接样式。Gets or sets the join style for the ends of two consecutive lines drawn with this Pen. |
| MiterLimit |
获取或设置斜接角上联接宽度的限制。Gets or sets the limit of the thickness of the join on a mitered corner. |
| PenType |
获取用此 Pen 绘制的直线的样式。Gets the style of lines drawn with this Pen. |
| StartCap |
获取或设置在通过此 Pen 绘制的直线起点使用的线帽样式。Gets or sets the cap style used at the beginning of lines drawn with this Pen. |
| Transform |
获取或设置此 Pen 的几何变换的副本。Gets or sets a copy of the geometric transformation for this Pen. |
| Width |
获取或设置此 Pen 的宽度,以用于绘图的 Graphics 对象为单位。Gets or sets the width of this Pen, in units of the Graphics object used for drawing. |
方法
| Clone() | |
| CreateObjRef(Type) |
创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (继承自 MarshalByRefObject) |
| Dispose() | |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| Finalize() |
在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetLifetimeService() |
已过时。
检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance. (继承自 MarshalByRefObject) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| InitializeLifetimeService() |
已过时。
获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance. (继承自 MarshalByRefObject) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| MemberwiseClone(Boolean) |
创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object. (继承自 MarshalByRefObject) |
| MultiplyTransform(Matrix) |
用指定的 Matrix 乘以此 Pen 的转换矩阵。Multiplies the transformation matrix for this Pen by the specified Matrix. |
| MultiplyTransform(Matrix, MatrixOrder) |
按照指定的顺序,用指定的 Matrix 乘以此 Pen 的变换矩阵。Multiplies the transformation matrix for this Pen by the specified Matrix in the specified order. |
| ResetTransform() |
将此 Pen 的几何变换矩阵重置为单位矩阵。Resets the geometric transformation matrix for this Pen to identity. |
| RotateTransform(Single) |
将局部几何转换旋转指定角度。Rotates the local geometric transformation by the specified angle. 此方法将旋转添加到转换前。This method prepends the rotation to the transformation. |
| RotateTransform(Single, MatrixOrder) |
以指定顺序将局部几何变换旋转指定角度。Rotates the local geometric transformation by the specified angle in the specified order. |
| ScaleTransform(Single, Single) |
按指定因子缩放局部几何变换。Scales the local geometric transformation by the specified factors. 此方法将缩放矩阵添加到转换前。This method prepends the scaling matrix to the transformation. |
| ScaleTransform(Single, Single, MatrixOrder) |
将局部几何变换以指定顺序缩放指定因子。Scales the local geometric transformation by the specified factors in the specified order. |
| SetLineCap(LineCap, LineCap, DashCap) |
设置用于确定线帽样式的值,线帽用于结束通过此 Pen 绘制的直线。Sets the values that determine the style of cap used to end lines drawn by this Pen. |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
| TranslateTransform(Single, Single) |
将局部几何转换平移指定尺寸。Translates the local geometric transformation by the specified dimensions. 此方法将平移添加到转换前。This method prepends the translation to the transformation. |
| TranslateTransform(Single, Single, MatrixOrder) |
按指定的顺序将局部几何变换平移指定的尺寸。Translates the local geometric transformation by the specified dimensions in the specified order. |