Pen 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義用來繪製線條和曲線的物件。 無法繼承這個類別。
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方法,傳遞e為 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
備註
A Pen 畫一條寬度與風格的線。 利用該 DashStyle 性質繪製多種虛線。 由 所 Pen 繪製的線條可以用多種填充方式填充,包括純色和材質。 填充風格取決於用作填充物件的刷子或材質。
備註
在 .NET 6 和更新版本中,只有 Windows作系統才支援包含此類型的 System.Drawing.Common 套件。 跨平台應用程式使用此類會引發編譯時警告及執行時異常。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common。
建構函式
| 名稱 | Description |
|---|---|
| Pen(Brush, Single) | |
| Pen(Brush) | |
| Pen(Color, Single) | |
| Pen(Color) |
初始化一個以指定顏色的新類別實例 Pen 。 |
屬性
| 名稱 | Description |
|---|---|
| Alignment |
取得或設定此對 Pen齊。 |
| Brush | |
| 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 |