Pen Costruttori
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della Pen classe con il colore specificato.
Overload
| Nome | Descrizione |
|---|---|
| Pen(Brush) |
Inizializza una nuova istanza della Pen classe con l'oggetto specificato Brush. |
| Pen(Color) |
Inizializza una nuova istanza della Pen classe con il colore specificato. |
| Pen(Brush, Single) |
Inizializza una nuova istanza della Pen classe con l'oggetto e WidthspecificatoBrush. |
| Pen(Color, Single) |
Inizializza una nuova istanza della Pen classe con le proprietà e Width specificateColor. |
Pen(Brush)
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
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)
Parametri
Eccezioni
brush è null.
Esempio
Nell'esempio di codice seguente viene illustrata la creazione di un Pen oggetto con e Brush gli effetti dell'impostazione della LineJoin proprietà su un oggetto Pen.
Questo esempio è progettato per essere usato con Windows Form. Incollare il codice in una maschera e chiamare il ShowLineJoin metodo quando si gestisce l'evento del Paint modulo, passando e come 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
Commenti
La Brush proprietà determina la modalità di disegno delle Pen linee. Le linee vengono disegnate come se fossero rettangoli riempiti, con le caratteristiche dell'oggetto specificato Brush.
La Width proprietà del nuovo Pen è impostata su 1 (impostazione predefinita).
Si applica a
Pen(Color)
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
Inizializza una nuova istanza della Pen classe con il colore specificato.
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)
Parametri
Commenti
La Color proprietà è impostata sul colore specificato dal color parametro . La Width proprietà è impostata su 1 (impostazione predefinita).
Si applica a
Pen(Brush, Single)
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
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)
Parametri
Eccezioni
brush è null.
Esempio
Nell'esempio di codice seguente viene creato un Pen oggetto e vengono illustrati gli effetti dell'impostazione delle StartCap proprietà e EndCap in un oggetto Pen.
Questo esempio è progettato per essere usato con Windows Form. Incollare il codice in una maschera e chiamare il ShowStartAndEndCaps metodo quando si gestisce l'evento del Paint modulo, passando e come 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
Commenti
l'oggetto Brush viene impostato sul colore specificato nel brush parametro , la Width proprietà viene impostata sul valore specificato nel width parametro e le unità vengono impostate Worldsu .
Si noti che il brush parametro specifica anche la Color proprietà di questo Penoggetto .
Se questo valore è 0, la larghezza in unità dispositivo è sempre 1 pixel, non è influenzata dalle operazioni di trasformazione della scala applicate per l'oggetto Pen Graphics utilizzato da .
Si applica a
Pen(Color, Single)
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
- Origine:
- Pen.cs
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)
Parametri
Esempio
Nell'esempio di codice seguente viene illustrata la creazione di un Pen oggetto e gli effetti dell'impostazione delle DashCapproprietà , DashPatterne SmoothingMode .
Questo esempio è progettato per essere usato con Windows Form. Incollare il codice in una maschera e chiamare il metodo quando si gestisce l'evento ShowPensAndSmoothingMode del Paint modulo, passando e come 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
Commenti
La Color proprietà è impostata sul colore specificato dal color parametro . La Width proprietà viene impostata sul valore specificato nel width parametro . Se questo valore è 0, la larghezza in unità dispositivo è sempre 1 pixel, non è influenzata dalle operazioni di trasformazione della scala applicate per l'oggetto Pen Graphics utilizzato da .