Pen 类

定义用于绘制直线和曲线的对象。无法继承此类。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public NotInheritable Class Pen
    Inherits MarshalByRefObject
    Implements ICloneable, IDisposable
用法
Dim instance As Pen
public sealed class Pen : MarshalByRefObject, ICloneable, IDisposable
public ref class Pen sealed : public MarshalByRefObject, ICloneable, IDisposable
public final class Pen extends MarshalByRefObject implements ICloneable, IDisposable
public final class Pen extends MarshalByRefObject implements ICloneable, IDisposable

备注

Pen 绘制指定宽度和样式的直线。使用 DashStyle 属性绘制几种虚线。可以使用各种填充样式(包括纯色和纹理)来填充 Pen 绘制的直线。填充模式取决于画笔或用作填充对象的纹理。

示例

下面的代码示例演示了如何使用 Brush 构造 Pen,以及在 Pen 上设置 LineJoin 属性的效果。

此示例是针对使用 Windows 窗体而设计的。将代码粘贴到一个窗体中,然后在处理窗体的 Paint 事件时调用 ShowLineJoin 方法,并传递 e 作为 PaintEventArgs

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
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:
   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.get_DeepSkyBlue());

    // Set the pen's width.
    skyBluePen.set_Width(8);

    // Set the LineJoin property.
    skyBluePen.set_LineJoin(System.Drawing.Drawing2D.LineJoin.Bevel);

    // Draw a rectangle.
    e.get_Graphics().DrawRectangle(skyBluePen, 
        new Rectangle(40, 40, 150, 200));

    //Dispose of the pen.
    skyBluePen.Dispose();
} //ShowLineJoin

继承层次结构

System.Object
   System.MarshalByRefObject
    System.Drawing.Pen

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Pen 成员
System.Drawing 命名空间