次の方法で共有


Pen コンストラクター

定義

指定した色を使用して、 Pen クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
Pen(Brush)

指定したPenを使用して、Brush クラスの新しいインスタンスを初期化します。

Pen(Color)

指定した色を使用して、 Pen クラスの新しいインスタンスを初期化します。

Pen(Brush, Single)

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

Pen(Color, Single)

指定したColorプロパティとWidthプロパティを使用して、Pen クラスの新しいインスタンスを初期化します。

Pen(Brush)

ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs

指定したPenを使用して、Brush クラスの新しいインスタンスを初期化します。

public:
 Pen(System::Drawing::Brush ^ brush);
public Pen(System.Drawing.Brush brush);
new System.Drawing.Pen : System.Drawing.Brush -> System.Drawing.Pen
Public Sub New (brush As Brush)

パラメーター

brush
Brush

このPenの塗りつぶしプロパティを決定するBrush

例外

brushnullです。

次のコード例では、Brushを使用してPenを構築し、PenLineJoin プロパティを設定する効果を示します。

この例は、Windows フォームで使用するように設計されています。 フォームにコードを貼り付け、フォームのPaint イベントを処理するときにShowLineJoin メソッドを呼び出し、PaintEventArgsとしてe渡します。

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

注釈

Brushプロパティは、Penが線を描画する方法を決定します。 線は、指定した Brushの特性を持つ塗りつぶされた四角形であるかのように描画されます。

新しいPenWidth プロパティは 1 (既定値) に設定されます。

適用対象

Pen(Color)

ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs

指定した色を使用して、 Pen クラスの新しいインスタンスを初期化します。

public:
 Pen(System::Drawing::Color color);
public Pen(System.Drawing.Color color);
new System.Drawing.Pen : System.Drawing.Color -> System.Drawing.Pen
Public Sub New (color As Color)

パラメーター

color
Color

このPenの色を示すColor構造体。

注釈

Color プロパティは、color パラメーターで指定された色に設定されます。 Width プロパティは 1 (既定値) に設定されています。

適用対象

Pen(Brush, Single)

ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs

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

public:
 Pen(System::Drawing::Brush ^ brush, float width);
public Pen(System.Drawing.Brush brush, float width);
new System.Drawing.Pen : System.Drawing.Brush * single -> System.Drawing.Pen
Public Sub New (brush As Brush, width As Single)

パラメーター

brush
Brush

このPenの特性を決定するBrush

width
Single

新しい Penの幅。

例外

brushnullです。

次のコード例では、Penを作成し、Penに対してStartCapプロパティとEndCapプロパティを設定する効果を示します。

この例は、Windows フォームで使用するように設計されています。 フォームにコードを貼り付け、フォームのPaint イベントを処理するときにShowStartAndEndCaps メソッドを呼び出し、PaintEventArgsとしてe渡します。

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(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 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

注釈

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

brush パラメーターは、このPenColor プロパティも指定します。

この値が 0 の場合、デバイス単位の幅は常に 1 ピクセルです。 Pen が使用される Graphics オブジェクトに対して有効なスケール変換操作の影響を受けません。

適用対象

Pen(Color, Single)

ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs
ソース:
Pen.cs

指定したColorプロパティとWidthプロパティを使用して、Pen クラスの新しいインスタンスを初期化します。

public:
 Pen(System::Drawing::Color color, float width);
public Pen(System.Drawing.Color color, float width);
new System.Drawing.Pen : System.Drawing.Color * single -> System.Drawing.Pen
Public Sub New (color As Color, width As Single)

パラメーター

color
Color

このPenの色を示すColor構造体。

width
Single

この Penの幅を示す値。

次のコード例では、 Pen の作成と、 DashCapDashPattern、および SmoothingMode プロパティの設定の効果を示します。

この例は、Windows フォームで使用するように設計されています。 フォームにコードを貼り付け、フォームの Paint イベントを処理するときに ShowPensAndSmoothingMode メソッドを呼び出し、e をPaintEventArgsとして渡します。

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.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 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

注釈

Color プロパティは、color パラメーターで指定された色に設定されます。 Width プロパティは、width パラメーターで指定された値に設定されます。 この値が 0 の場合、デバイス単位の幅は常に 1 ピクセルです。 Pen が使用される Graphics オブジェクトに対して有効なスケール変換操作の影響を受けません。

適用対象