Pen 생성자

정의

지정된 색을 사용하여 Pen 클래스의 새 인스턴스를 초기화합니다.

오버로드

Pen(Brush)

지정된 Pen를 사용하여 Brush 클래스의 새 인스턴스를 초기화합니다.

Pen(Color)

지정된 색을 사용하여 Pen 클래스의 새 인스턴스를 초기화합니다.

Pen(Brush, Single)

지정된 PenBrush를 사용하여 Width 클래스의 새 인스턴스를 초기화합니다.

Pen(Color, Single)

지정된 PenColor속성을 사용하여 Width 클래스의 새 인스턴스를 초기화합니다.

Pen(Brush)

지정된 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

Brush의 채우기 속성을 결정하는 Pen입니다.

예외

brush이(가) null인 경우

예제

다음 코드 예제에서는 a Brush 와 속성을 설정 LineJoin 하는 효과 생성 Pen 하는 방법을 Pen보여 줍니다.

이 예제는 Windows Forms 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 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

설명

속성은 Brush 선을 그리는 Pen 방법을 결정합니다. 선은 지정된 Brush특성으로 채워진 사각형처럼 그려집니다.

Pen 속성은 Width 1(기본값)으로 설정됩니다.

적용 대상

Pen(Color)

지정된 색을 사용하여 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

Color의 색을 나타내는 Pen 구조체입니다.

설명

Color 속성은 매개 변수에 지정된 색으로 color 설정됩니다. 속성은 Width 1(기본값)으로 설정됩니다.

적용 대상

Pen(Brush, Single)

지정된 PenBrush를 사용하여 Width 클래스의 새 인스턴스를 초기화합니다.

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

Brush의 특성을 결정하는 Pen입니다.

width
Single

Pen의 너비입니다.

예외

brush이(가) null인 경우

예제

다음 코드 예제에서는 a를 Pen 만들고 설정 StartCap EndCap 하 고 속성에 Pen미치는 영향을 보여 줍니다.

이 예제는 Windows Forms 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 Paint 이벤트를 처리할 때 메서드를 호출 ShowStartAndEndCaps 하여 전달 e 합니다PaintEventArgs.

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됩니다.

매개 변수는 brushPen속성도 Color 지정합니다.

이 값이 0이면 디바이스 단위의 너비는 항상 1픽셀— 이며 사용되는 Graphics 개체 Pen 에 적용되는 크기 조정 변환 작업의 영향을 받지 않습니다.

적용 대상

Pen(Color, Single)

지정된 PenColor속성을 사용하여 Width 클래스의 새 인스턴스를 초기화합니다.

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

Color의 색을 나타내는 Pen 구조체입니다.

width
Single

Pen의 너비를 나타내는 값입니다.

예제

다음 코드 예제에서는 만들기 Pen 및 설정DashCap의 효과 보여 DashPatternSmoothingMode 줍니다.

이 예제는 Windows Forms 사용하도록 설계되었습니다. Paste the code into a form and call the ShowPensAndSmoothingMode method when handling the form's Paint event, passing e as 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픽셀— 이며 사용되는 Graphics 개체 Pen 에 적용되는 크기 조정 변환 작업의 영향을 받지 않습니다.

적용 대상