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 Forms 搭配使用。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. 填滿樣式取決於當做 fill 物件使用的筆刷或材質。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) |
使用指定的 Color 和 Width 屬性,初始化 Pen 類別的新執行個體。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) |
建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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() |
已過時。
擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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) |
將這個 Pen 的轉換矩陣乘以指定的 Matrix。Multiplies the transformation matrix for this Pen by the specified Matrix. |
MultiplyTransform(Matrix, MatrixOrder) |
依照指定的順序,將這個 Pen 的轉換矩陣乘以指定的 Matrix。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. |