Pen Pen Pen Constructors

Определение

Перегрузки

Pen(Brush) Pen(Brush) Pen(Brush)

Инициализирует новый экземпляр класса Pen указанным значением Brush.Initializes a new instance of the Pen class with the specified Brush.

Pen(Color) Pen(Color) Pen(Color)

Инициализирует новый экземпляр класса Pen с указанным цветом.Initializes a new instance of the Pen class with the specified color.

Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single)

Инициализирует новый экземпляр Pen с заданными объектами Brush и Width.Initializes a new instance of the Pen class with the specified Brush and Width.

Pen(Color, Single) Pen(Color, Single) Pen(Color, Single)

Инициализирует новый экземпляр класса Pen с указанными свойствами Color и Width.Initializes a new instance of the Pen class with the specified Color and Width properties.

Pen(Brush) Pen(Brush) Pen(Brush)

Инициализирует новый экземпляр класса Pen указанным значением Brush.Initializes a new instance of the Pen class with the specified Brush.

public:
 Pen(System::Drawing::Brush ^ brush);
public Pen (System.Drawing.Brush brush);
new System.Drawing.Pen : System.Drawing.Brush -> System.Drawing.Pen

Параметры

brush
Brush Brush Brush

Объект Brush, определяющий свойства заполнения объекта Pen.A Brush that determines the fill properties of this Pen.

Исключения

Примеры

В следующем примере кода демонстрируется создание Pen с Brush и последствия параметр LineJoin свойство Pen.The following code example demonstrates constructing a Pen with a Brush and the effects of setting the LineJoin property on a Pen.

Этот пример предназначен для использования с Windows Forms.This example is designed to be used with Windows Forms. Вставьте код в форму и вызовите ShowLineJoin метод при обработке формы Paint передачи событий e как PaintEventArgs.Paste the code into a form and call the ShowLineJoin method when handling the form's Paint event, passing e as 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 рисуются линии.The Brush property determines how the Pen draws lines. Рисуются линии, как если бы они заполненных прямоугольников с характеристиками указанного Brush.Lines are drawn as if they are filled rectangles, with the characteristics of the specified Brush.

Width Свойства нового Pen имеет значение 1 (по умолчанию).The Width property of the new Pen is set to 1 (the default).

Pen(Color) Pen(Color) Pen(Color)

Инициализирует новый экземпляр класса Pen с указанным цветом.Initializes a new instance of the Pen class with the specified color.

public:
 Pen(System::Drawing::Color color);
public Pen (System.Drawing.Color color);
new System.Drawing.Pen : System.Drawing.Color -> System.Drawing.Pen

Параметры

color
Color Color Color

Структура Color, показывающая цвет объекта Pen.A Color structure that indicates the color of this Pen.

Комментарии

Color Задано значение цвета, заданного color параметра.The Color property is set to the color specified by the color parameter. Width Свойство имеет значение 1 (по умолчанию).The Width property is set to 1 (the default).

Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single)

Инициализирует новый экземпляр Pen с заданными объектами Brush и Width.Initializes a new instance of the Pen class with the specified Brush and 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

Параметры

brush
Brush Brush Brush

Объект Brush, определяющий характеристики данного объекта Pen.A Brush that determines the characteristics of this Pen.

width
Single Single Single

Ширина нового пера Pen.The width of the new Pen.

Исключения

Примеры

В следующем примере кода создается Pen и демонстрируется действие параметра StartCap и EndCap свойства Pen.The following code example creates a Pen and demonstrates the effects of setting the StartCap and EndCap properties on a Pen.

Этот пример предназначен для использования с Windows Forms.This example is designed to be used with Windows Forms. Вставьте код в форму и вызовите ShowStartAndEndCaps метод при обработке формы Paint передачи событий e как PaintEventArgs.Paste the code into a form and call the ShowStartAndEndCaps method when handling the form's Paint event, passing e as 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.The Brush is set to the color specified in the brush parameter, the Width property is set to the value specified in the width parameter, and the units are set to World.

Обратите внимание, что brush также задает Color свойства данного объекта Pen.Note that the brush parameter also specifies the Color property of this Pen.

Объект width 0 приведет к Pen рисования, как если бы ширина была равна 1.A width of 0 will result in the Pen drawing as if the width were 1.

Pen(Color, Single) Pen(Color, Single) Pen(Color, Single)

Инициализирует новый экземпляр класса Pen с указанными свойствами Color и Width.Initializes a new instance of the Pen class with the specified Color and Width properties.

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

Параметры

color
Color Color Color

Структура Color, показывающая цвет объекта Pen.A Color structure that indicates the color of this Pen.

width
Single Single Single

Значение, показывающее ширину объекта Pen.A value indicating the width of this Pen.

Примеры

В следующем примере кода показано создание Pen и последствия параметр DashCap, DashPattern, и SmoothingMode свойства.The following code example demonstrates creating a Pen and the effects of setting the DashCap, DashPattern, and SmoothingMode properties.

Этот пример предназначен для использования с Windows Forms.This example is designed to be used with Windows Forms. Вставьте код в форму и вызовите ShowPensAndSmoothingMode метод при обработке формы Paint событий, передав e как PaintEventArgs.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 параметра.The Color property is set to the color specified by the color parameter. Width Свойству присваивается значение, указанное в width параметра.The Width property is set to the value specified in the width parameter. Объект width 0 приведет к Pen рисования, как если бы ширина была равна 1.A width of 0 will result in the Pen drawing as if the width were 1.

Применяется к