Pen 생성자

정의

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

오버로드

Pen(Brush)

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

Pen(Color)

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

Pen(Brush, Single)

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

Pen(Color, Single)

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

Pen(Brush)

Source:
Pen.cs
Source:
Pen.cs
Source:
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

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

예외

brush이(가) null인 경우

예제

다음 코드 예제를 생성 하는 방법을 Pen 보여 줍니다는 를 사용 하 고 Brush 설정의 LineJoin 효과 속성에 합니다 Pen.

이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 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의 특성을 사용하여 채워진 사각형처럼 그려집니다.

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

적용 대상

Pen(Color)

Source:
Pen.cs
Source:
Pen.cs
Source:
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

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

설명

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

적용 대상

Pen(Brush, Single)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

지정된 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인 경우

예제

다음 코드 예제를 만들고 Pen 설정의 StartCap 효과 보여 줍니다는 및 EndCap 속성을 에 합니다 Pen.

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

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

이 값이 0이면 디바이스 단위의 너비가 항상 1픽셀이므로 가 사용되는 Graphics 개체 Pen 에 적용되는 배율 변환 작업의 영향을 받지 않습니다.

적용 대상

Pen(Color, Single)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

지정된 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의 효과 , DashPattern, 및 SmoothingMode 속성입니다.

이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 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픽셀이므로 가 사용되는 Graphics 개체 Pen 에 적용되는 배율 변환 작업의 영향을 받지 않습니다.

적용 대상