Sdílet prostřednictvím


Pen Konstruktory

Definice

Inicializuje novou instanci Pen třídy se zadanou barvou.

Přetížení

Name Description
Pen(Brush)

Inicializuje novou instanci Pen třídy se zadaným Brush.

Pen(Color)

Inicializuje novou instanci Pen třídy se zadanou barvou.

Pen(Brush, Single)

Inicializuje novou instanci Pen třídy se zadaným Brush a Width.

Pen(Color, Single)

Inicializuje novou instanci Pen třídy se zadanými Color a Width vlastnostmi.

Pen(Brush)

Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs

Inicializuje novou instanci Pen třídy se zadaným 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)

Parametry

brush
Brush

A Brush , který určuje vlastnosti výplně tohoto Pen.

Výjimky

brush je null.

Příklady

Následující příklad kódu ukazuje vytvoření Pen s a Brush účinky nastavení LineJoin vlastnosti na .Pen

Tento příklad je navržený tak, aby se používal s Windows Forms. Vložte kód do formuláře a zavolejte metodu ShowLineJoin při zpracování události formuláře Paint a předejte e jako 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

Poznámky

Vlastnost Brush určuje způsob Pen nakreslování čar. Čáry jsou nakresleny tak, jako by byly vyplněné obdélníky s vlastnostmi zadaného Brush.

Vlastnost Width nové Pen je nastavena na hodnotu 1 (výchozí).

Platí pro

Pen(Color)

Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs

Inicializuje novou instanci Pen třídy se zadanou barvou.

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)

Parametry

color
Color

Struktura Color , která označuje barvu tohoto Pen.

Poznámky

Vlastnost Color je nastavena na barvu určenou parametrem color . Vlastnost Width je nastavena na hodnotu 1 (výchozí).

Platí pro

Pen(Brush, Single)

Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs

Inicializuje novou instanci Pen třídy se zadaným Brush a 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)

Parametry

brush
Brush

A Brush , který určuje charakteristiky tohoto Pen.

width
Single

Šířka nového Pensouboru .

Výjimky

brush je null.

Příklady

Následující příklad kódu vytvoří Pen a demonstruje účinky nastavení StartCap a EndCap vlastnosti na objektu Pen.

Tento příklad je navržený tak, aby se používal s Windows Forms. Vložte kód do formuláře a zavolejte metodu ShowStartAndEndCaps při zpracování události formuláře Paint a předejte e jako 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

Poznámky

Je Brush nastavena na barvu zadanou v parametru brush , Width vlastnost je nastavena na hodnotu zadanou v parametru width a jednotky jsou nastaveny na World.

Všimněte si, že brush parametr také určuje Color vlastnost tohoto Pen.

Pokud je tato hodnota 0, šířka v jednotkách zařízení je vždy 1 pixel – není ovlivněna operacemi transformace měřítka, které platí pro grafický objekt, pro Pen který se používá.

Platí pro

Pen(Color, Single)

Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs
Zdroj:
Pen.cs

Inicializuje novou instanci Pen třídy se zadanými Color a Width vlastnostmi.

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)

Parametry

color
Color

Struktura Color , která označuje barvu tohoto Pen.

width
Single

Hodnota označující šířku tohoto Penparametru .

Příklady

Následující příklad kódu ukazuje vytvoření Pen a účinky nastavení DashCap, DashPatterna SmoothingMode vlastnosti.

Tento příklad je navržený tak, aby se používal s Windows Forms. Vložte kód do formuláře a při zpracování události formuláře Paint zavolejte ShowPensAndSmoothingMode metodu e jako 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

Poznámky

Vlastnost Color je nastavena na barvu určenou parametrem color . Vlastnost Width je nastavena na hodnotu zadanou v parametru width . Pokud je tato hodnota 0, šířka v jednotkách zařízení je vždy 1 pixel – není ovlivněna operacemi transformace měřítka, které platí pro grafický objekt, pro Pen který se používá.

Platí pro