PENとは? わかりやすく解説

Pen クラス

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

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public NotInheritable Class
 Pen
    Inherits MarshalByRefObject
    Implements ICloneable, IDisposable
public sealed class Pen : MarshalByRefObject,
 ICloneable, IDisposable
public ref class Pen sealed : public
 MarshalByRefObject, ICloneable, IDisposable
public final class Pen extends MarshalByRefObject
 implements ICloneable, IDisposable
public final class Pen extends
 MarshalByRefObject implements ICloneable, IDisposable
解説解説
使用例使用例

次のコード例は、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.Object
   System.MarshalByRefObject
    System.Drawing.Pen
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Pen コンストラクタ (Color, Single)

指定Color プロパティWidth プロパティPen クラス新しインスタンス初期化します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

解説解説
使用例使用例

次のコード例では、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Pen コンストラクタ (Brush)

Brush指定してPen クラス新しインスタンス初期化します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

brushnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次のコード例は、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Pen コンストラクタ


Pen コンストラクタ (Brush, Single)

指定した BrushWidth使用してPen クラス新しインスタンス初期化します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

brushnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次のコード例では、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Pen コンストラクタ (Color)


Pen プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Width この Pen の幅を取得または設定します
参照参照

Pen メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clone 対象の Pen の同一コピー作成します
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信使用するプロキシ生成必要な情報をすべて格納しているオブジェクト作成します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド Dispose この Pen によって使用されているすべてのリソース解放します。
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetLifetimeService  対象インスタンス有効期間ポリシー制御する現在の有効期間サービス オブジェクト取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象インスタンス有効期間ポリシー制御する有効期間サービス オブジェクト取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド MultiplyTransform オーバーロードされます。 この Pen変換行列指定Matrix乗算ます。
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ResetTransform 対象Penジオメトリック変換行列単位行列リセットします。
パブリック メソッド RotateTransform オーバーロードされます指定した角度だけローカル ジオメトリック変換回転します。このメソッド変換前に回転行います
パブリック メソッド ScaleTransform オーバーロードされます指定した係数だけローカル ジオメトリック変換スケーリングます。このメソッド変換前にスケーリング行列適用します。
パブリック メソッド SetLineCap この Pen描画する直線終了させるとき、使用されるキャップスタイル決定する値を設定します
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
パブリック メソッド TranslateTransform オーバーロードされます指定した寸法ローカル ジオメトリック変換平行移動ます。このメソッド変換前に平行移動行います
プロテクト メソッドプロテクト メソッド
参照参照

Pen メンバ

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

Pen データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Width この Pen の幅を取得または設定します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clone 対象Pen同一コピー作成します
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信使用するプロキシ生成必要な情報をすべて格納しているオブジェクト作成します。 (MarshalByRefObject から継承されます。)
パブリック メソッド Dispose この Pen によって使用されているすべてのリソース解放します。
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetLifetimeService  対象インスタンス有効期間ポリシー制御する現在の有効期間サービス オブジェクト取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象インスタンス有効期間ポリシー制御する有効期間サービス オブジェクト取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド MultiplyTransform オーバーロードされます。 この Pen変換行列指定Matrix乗算ます。
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ResetTransform 対象Penジオメトリック変換行列単位行列リセットします。
パブリック メソッド RotateTransform オーバーロードされます指定した角度だけローカル ジオメトリック変換回転します。このメソッド変換前に回転行います
パブリック メソッド ScaleTransform オーバーロードされます指定した係数だけローカル ジオメトリック変換スケーリングます。このメソッド変換前にスケーリング行列適用します。
パブリック メソッド SetLineCap この Pen描画する直線終了させるとき、使用されるキャップスタイル決定する値を設定します
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
パブリック メソッド TranslateTransform オーバーロードされます指定した寸法ローカル ジオメトリック変換平行移動ます。このメソッド変換前に平行移動行います
プロテクト メソッドプロテクト メソッド
参照参照




PENと同じ種類の言葉

このページでは「.NET Framework クラス ライブラリ リファレンス」からPENを検索した結果を表示しています。
Weblioに収録されているすべての辞書からPENを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からPEN を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「PEN」の関連用語

PENのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



PENのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS