共用方式為


Pen 類別

定義

定義用來繪製線條和曲線的物件。 無法繼承這個類別。

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 a 的 a Brush ,以及將屬性設定 LineJoin 在 a Pen上的影響。

此範例設計用於 Windows 表單。 將程式碼貼到表單中,處理表單Paint事件時呼叫該ShowLineJoin方法,傳遞ePaintEventArgs

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

備註

A Pen 畫一條寬度與風格的線。 利用該 DashStyle 性質繪製多種虛線。 由 所 Pen 繪製的線條可以用多種填充方式填充,包括純色和材質。 填充風格取決於用作填充物件的刷子或材質。

備註

在 .NET 6 和更新版本中,只有 Windows作系統才支援包含此類型的 System.Drawing.Common 套件。 跨平台應用程式使用此類會引發編譯時警告及執行時異常。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common。

建構函式

名稱 Description
Pen(Brush, Single)

初始化一個新的類別實例 Pen ,並指定為 BrushWidth和 。

Pen(Brush)

初始化一個新的類別實例 Pen ,並指定為 Brush

Pen(Color, Single)

初始化一個具有指定Color屬性Width的類別新實例Pen

Pen(Color)

初始化一個以指定顏色的新類別實例 Pen

屬性

名稱 Description
Alignment

取得或設定此對 Pen齊。

Brush

取得或設定 , Brush 決定了該 Pen屬性。

Color

取得或設定此顏色 Pen

CompoundArray

取得或設定一個數值陣列,指定複合筆。 複合筆會畫出由平行線條和空格組成的複合線。

CustomEndCap

取得或設定一個自訂上限,用於用此 Pen方法畫出的線條末尾。

CustomStartCap

會取得或設定自訂上限,在用這個 Pen畫的線條開始時使用。

DashCap

取得或設定在組成虛線 Pen的破折線末尾所使用的頂帽風格。

DashOffset

取得或設定從一條線起點到劃線圖案起點的距離。

DashPattern

可以取得或設定一系列自訂的破折號和空格。

DashStyle

取得或設定用此 Pen畫的虛線所用的樣式。

EndCap

取得或設定使用此 Pen畫線條末尾的帽型樣式。

LineJoin

取得或設定兩條連續 Pen直線端點的連接風格。

MiterLimit

設定或限制斜接角接合處的厚度上限。

PenType

用這個 Pen畫出那種線條風格。

StartCap

取得或設定使用此 Pen線條開頭所用的帽型樣式。

Transform

取得或設定此 Pen幾何變換的副本。

Width

以繪圖物件為單位來取得或設定此PenGraphics寬度。

方法

名稱 Description
Clone()

會建立一個完全相同的複製品。Pen

CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()

釋放所有被使用。Pen

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

允許物件嘗試釋放資源並執行其他清理操作,然後再被垃圾回收回收。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

取得目前控制此實例生命週期政策的終身服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得一個終身服務物件以控制此實例的終身政策。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立一個 MarshalByRefObject 目前物件的淺層複製品。

(繼承來源 MarshalByRefObject)
MultiplyTransform(Matrix, MatrixOrder)

將此 Pen 轉換矩陣乘以 Matrix 指定順序的 。

MultiplyTransform(Matrix)

將此 Pen 轉換矩陣乘以指定的 Matrix

ResetTransform()

將此 Pen 幾何變換矩陣重置為恆等。

RotateTransform(Single, MatrixOrder)

以指定角度以指定順序旋轉局部幾何變換。

RotateTransform(Single)

將局部幾何變換旋轉至指定角度。 此方法在轉換前先行旋轉。

ScaleTransform(Single, Single, MatrixOrder)

以指定因子以指定階數縮放局部幾何變換。

ScaleTransform(Single, Single)

以指定因子縮放局部幾何變換。 此方法在變換前加上縮放矩陣。

SetLineCap(LineCap, LineCap, DashCap)

設定決定用來結束線 Pen條的帽型樣式的值。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
TranslateTransform(Single, Single, MatrixOrder)

將局部幾何變換轉換為指定維度並按指定順序進行平算。

TranslateTransform(Single, Single)

將局部幾何變換換成指定的維度。 此方法在轉換前置於平移前。

適用於