Pen クラス
アセンブリ: System.Drawing (system.drawing.dll 内)

Public NotInheritable Class Pen Inherits MarshalByRefObject Implements ICloneable, IDisposable
public sealed class Pen : 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 イベントを処理するときに PaintEventArgs の e を渡して ShowLineJoin メソッドを呼び出します。
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.MarshalByRefObject
System.Drawing.Pen


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Pen コンストラクタ (Color, Single)
アセンブリ: System.Drawing (system.drawing.dll 内)


Color プロパティは color パラメータで指定された色に設定されます。Width プロパティは width パラメータに指定された値に設定されます。width に 0 を指定した場合は、1 が指定されたものと見なされて Pen の描画が行われます。

次のコード例では、Pen を作成し、DashCapプロパティ、DashPattern プロパティ、および SmoothingMode プロパティを設定することの効果を示します。
この例は、Windows フォームでの使用を意図してデザインされています。このコードをフォームに貼り付け、フォームの Paint イベントを処理するときに PaintEventArgs の e を渡して ShowPensAndSmoothingMode メソッドを呼び出します。
Private Sub ShowPensAndSmoothingMode(ByVal e As PaintEventArgs) ' Set the SmoothingMode property to smooth the line. e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias ' Create a new Pen object. Dim greenPen As New Pen(Color.Green) ' Set the width to 6. greenPen.Width = 6.0F ' Set the DashCap to round. greenPen.DashCap = Drawing2D.DashCap.Round ' Create a custom dash pattern. greenPen.DashPattern = New Single() {4.0F, 2.0F, 1.0F, 3.0F} ' Draw a line. e.Graphics.DrawLine(greenPen, 20.0F, 20.0F, 100.0F, 240.0F) ' Change the SmoothingMode to none. e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None ' Draw another line. e.Graphics.DrawLine(greenPen, 100.0F, 240.0F, 160.0F, 20.0F) ' Dispose of the custom pen. greenPen.Dispose() End Sub
private void ShowPensAndSmoothingMode(PaintEventArgs e) { // Set the SmoothingMode property to smooth the line. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Create a new Pen object. Pen greenPen = new Pen(Color.Green); // Set the width to 6. greenPen.Width = 6.0F; // Set the DashCap to round. greenPen.DashCap = System.Drawing.Drawing2D.DashCap.Round; // Create a custom dash pattern. greenPen.DashPattern = new float[]{4.0F, 2.0F, 1.0F, 3.0F}; // Draw a line. e.Graphics.DrawLine(greenPen, 20.0F, 20.0F, 100.0F, 240.0F); // Change the SmoothingMode to none. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; // Draw another line. e.Graphics.DrawLine(greenPen, 100.0F, 240.0F, 160.0F, 20.0F); // Dispose of the custom pen. greenPen.Dispose(); }
private: void ShowPensAndSmoothingMode( PaintEventArgs^ e ) { // Set the SmoothingMode property to smooth the line. e->Graphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::AntiAlias; // Create a new Pen object. Pen^ greenPen = gcnew Pen( Color::Green ); // Set the width to 6. greenPen->Width = 6.0F; // Set the DashCap to round. greenPen->DashCap = System::Drawing::Drawing2D::DashCap::Round; // Create a custom dash pattern. array<Single>^temp0 = {4.0F,2.0F,1.0F,3.0F}; greenPen->DashPattern = temp0; // Draw a line. e->Graphics->DrawLine( greenPen, 20.0F, 20.0F, 100.0F, 240.0F ); // Change the SmoothingMode to none. e->Graphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::None; // Draw another line. e->Graphics->DrawLine( greenPen, 100.0F, 240.0F, 160.0F, 20.0F ); // Dispose of the custom pen. delete greenPen; }
private void ShowPensAndSmoothingMode(PaintEventArgs e) { // Set the SmoothingMode property to smooth the line. e.get_Graphics().set_SmoothingMode( System.Drawing.Drawing2D.SmoothingMode.AntiAlias); // Create a new Pen object. Pen greenPen = new Pen(Color.get_Green()); // Set the width to 6. greenPen.set_Width(6); // Set the DashCap to round. greenPen.set_DashCap(System.Drawing.Drawing2D.DashCap.Round); // Create a custom dash pattern. greenPen.set_DashPattern(new float[] { 4, 2, 1, 3 }); // Draw a line. e.get_Graphics().DrawLine(greenPen, 20, 20, 100, 240); // Change the SmoothingMode to none. e.get_Graphics().set_SmoothingMode( System.Drawing.Drawing2D.SmoothingMode.None); // Draw another line. e.get_Graphics().DrawLine(greenPen, 100, 240, 160, 20); // Dispose of the custom pen. greenPen.Dispose(); } //ShowPensAndSmoothingMode

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Pen コンストラクタ (Brush)
アセンブリ: System.Drawing (system.drawing.dll 内)




次のコード例は、Brush を使用して Pen を作成する方法と、Pen で LineJoin プロパティを設定することの効果を示しています。
この例は、Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、フォームの Paint イベントを処理するときに PaintEventArgs の e を渡して ShowLineJoin メソッドを呼び出します。
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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Pen コンストラクタ

名前 | 説明 |
---|---|
Pen (Brush) | Brush を指定して、Pen クラスの新しいインスタンスを初期化します。 |
Pen (Color) | 指定した色を使用して、Pen クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
Pen (Brush, Single) | 指定した Brush と Width を使用して、Pen クラスの新しいインスタンスを初期化します。 |
Pen (Color, Single) | 指定の Color プロパティと Width プロパティで Pen クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

Pen コンストラクタ (Brush, Single)
アセンブリ: System.Drawing (system.drawing.dll 内)



Brush は brush パラメータで指定された色に、Width プロパティは width パラメータで指定された値に、単位は World にそれぞれ設定されます。

次のコード例では、Pen を作成し、Pen で StartCap プロパティおよび EndCap プロパティを設定することの効果を示します。
この例は、Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、フォームの Paint イベントを処理するときに PaintEventArgs の e を渡して ShowStartAndEndCaps メソッドを呼び出します。
Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click Dim buttonGraphics As Graphics = Button3.CreateGraphics() Dim myPen As Pen = New Pen(Color.ForestGreen, 4.0F) myPen.DashStyle = Drawing2D.DashStyle.DashDotDot Dim theRectangle As Rectangle = Button3.ClientRectangle theRectangle.Inflate(-2, -2) buttonGraphics.DrawRectangle(myPen, theRectangle) buttonGraphics.Dispose() myPen.Dispose() End Sub
private void Button3_Click(System.Object sender, System.EventArgs e) { Graphics buttonGraphics = Button3.CreateGraphics(); Pen myPen = new Pen(Color.ForestGreen, 4.0F); myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; Rectangle theRectangle = Button3.ClientRectangle; theRectangle.Inflate(-2, -2); buttonGraphics.DrawRectangle(myPen, theRectangle); buttonGraphics.Dispose(); myPen.Dispose(); }
private: void Button3_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { Graphics^ buttonGraphics = Button3->CreateGraphics(); Pen^ myPen = gcnew Pen( Color::ForestGreen,4.0F ); myPen->DashStyle = System::Drawing::Drawing2D::DashStyle::DashDotDot; Rectangle theRectangle = Button3->ClientRectangle; theRectangle.Inflate( -2, -2 ); buttonGraphics->DrawRectangle( myPen, theRectangle ); delete buttonGraphics; delete myPen; }
private void button3_Click(Object sender, System.EventArgs e) { Graphics buttonGraphics = button3.CreateGraphics(); Pen myPen = new Pen(Color.get_ForestGreen(), 4.0F); myPen.set_DashStyle(System.Drawing.Drawing2D.DashStyle.DashDotDot); Rectangle theRectangle = button3.get_ClientRectangle(); theRectangle.Inflate(-2, -2); buttonGraphics.DrawRectangle(myPen, theRectangle); buttonGraphics.Dispose(); myPen.Dispose(); } //button3_Click

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Pen コンストラクタ (Color)
アセンブリ: System.Drawing (system.drawing.dll 内)



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Pen プロパティ
Pen メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

Pen メンバ
直線および曲線の描画に使用するオブジェクトを定義します。このクラスは継承できません。




名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

pen.と同じ種類の言葉
Weblioに収録されているすべての辞書からpen.を検索する場合は、下記のリンクをクリックしてください。

- pen.のページへのリンク