Pen Pen Pen Pen Class

定義

定義用來繪製直線與曲線的物件。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上的屬性PenThe following code example demonstrates constructing a Pen with a Brush and the effects of setting the LineJoin property on a Pen.

這個範例被設計來搭配 Windows Form。This example is designed to be used with Windows Forms. 將程式碼貼入表單並呼叫ShowLineJoin方法時處理表單Paint事件,傳遞e做為PaintEventArgsPaste 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

備註

APen繪製指定的寬度和樣式的線條。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) Pen(Brush) Pen(Brush)

使用指定的 Pen 初始化 Brush 類別的新執行個體。Initializes a new instance of the Pen class with the specified Brush.

Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single)

使用指定的 PenBrush,初始化 Width 類別的新執行個體。Initializes a new instance of the Pen class with the specified Brush and Width.

Pen(Color) Pen(Color) Pen(Color) Pen(Color)

使用指定的色彩,初始化 Pen 類別的新執行個體。Initializes a new instance of the Pen class with the specified color.

Pen(Color, Single) Pen(Color, Single) Pen(Color, Single) Pen(Color, Single)

使用指定的 PenColor 屬性,初始化 Width 類別的新執行個體。Initializes a new instance of the Pen class with the specified Color and Width properties.

屬性

Alignment Alignment Alignment Alignment

取得或設定這個 Pen 的對齊。Gets or sets the alignment for this Pen.

Brush Brush Brush Brush

取得或設定 Brush,判斷這個 Pen 的屬性 (Attribute)。Gets or sets the Brush that determines attributes of this Pen.

Color Color Color Color

取得或設定這個 Pen 的色彩。Gets or sets the color of this Pen.

CompoundArray CompoundArray CompoundArray 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 CustomEndCap CustomEndCap CustomEndCap

取得或設定自訂帽緣,用於以這個 Pen 所繪製的直線末端。Gets or sets a custom cap to use at the end of lines drawn with this Pen.

CustomStartCap CustomStartCap CustomStartCap CustomStartCap

取得或設定自訂帽緣,用於以這個 Pen 所繪製的直線開端。Gets or sets a custom cap to use at the beginning of lines drawn with this Pen.

DashCap DashCap DashCap 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 DashOffset DashOffset DashOffset

取得或設定從直線開端至虛線圖樣開端的距離。Gets or sets the distance from the start of a line to the beginning of a dash pattern.

DashPattern DashPattern DashPattern DashPattern

取得或設定自訂虛線和間距的陣列。Gets or sets an array of custom dashes and spaces.

DashStyle DashStyle DashStyle DashStyle

取得或設定樣式,用於以這個 Pen 所繪製的短折線。Gets or sets the style used for dashed lines drawn with this Pen.

EndCap EndCap EndCap EndCap

取得或設定帽緣樣式,用於以這個 Pen 所繪製的直線末端。Gets or sets the cap style used at the end of lines drawn with this Pen.

LineJoin LineJoin LineJoin LineJoin

取得或設定以這個 Pen 所繪製之兩條連續直線末端的接合樣式。Gets or sets the join style for the ends of two consecutive lines drawn with this Pen.

MiterLimit MiterLimit MiterLimit MiterLimit

取得或設定斜接角上的接合厚度限制。Gets or sets the limit of the thickness of the join on a mitered corner.

PenType PenType PenType PenType

取得以這個 Pen 所繪製的直線樣式。Gets the style of lines drawn with this Pen.

StartCap StartCap StartCap StartCap

取得或設定帽緣樣式,用於以這個 Pen 所繪製的直線開端。Gets or sets the cap style used at the beginning of lines drawn with this Pen.

Transform Transform Transform Transform

取得或設定這個 Pen 幾何轉換的複本。Gets or sets a copy of the geometric transformation for this Pen.

Width Width Width Width

取得或設定這個 Pen 的寬度,以用於繪圖的 Graphics 物件為單位。Gets or sets the width of this Pen, in units of the Graphics object used for drawing.

方法

Clone() Clone() Clone() Clone()

建立這個 Pen 的完全相同複本。Creates an exact copy of this Pen.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

釋放這個 Pen 所使用的所有資源。Releases all resources used by this Pen.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix)

將這個 Pen 的轉換矩陣乘以指定的 MatrixMultiplies the transformation matrix for this Pen by the specified Matrix.

MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder)

依照指定的順序,將這個 Pen 的轉換矩陣乘以指定的 MatrixMultiplies the transformation matrix for this Pen by the specified Matrix in the specified order.

ResetTransform() ResetTransform() ResetTransform() ResetTransform()

將這個 Pen 的幾何轉換矩陣重設為單位矩陣。Resets the geometric transformation matrix for this Pen to identity.

RotateTransform(Single) RotateTransform(Single) RotateTransform(Single) RotateTransform(Single)

根據指定的角度來旋轉局部幾何轉換。Rotates the local geometric transformation by the specified angle. 這個方法會將旋轉附加到轉換之前。This method prepends the rotation to the transformation.

RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder)

依照指定的順序,根據指定的角度來旋轉局部幾何轉換。Rotates the local geometric transformation by the specified angle in the specified order.

ScaleTransform(Single, Single) ScaleTransform(Single, Single) ScaleTransform(Single, Single) 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) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder)

依照指定的順序,根據指定的因數來縮放局部幾何轉換。Scales the local geometric transformation by the specified factors in the specified order.

SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap)

設定值,判斷用於結束以這個 Pen 所繪製之直線的帽緣樣式。Sets the values that determine the style of cap used to end lines drawn by this Pen.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single)

根據指定的維度來轉換局部幾何轉換。Translates the local geometric transformation by the specified dimensions. 這個方法會將轉譯附加到轉換之前。This method prepends the translation to the transformation.

TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder)

依照指定的順序,根據指定的順序來轉換局部幾何轉換。Translates the local geometric transformation by the specified dimensions in the specified order.

適用於