Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der Pen-Klasse mit der angegebenen Color-Eigenschaft und der angegebenen Width-Eigenschaft.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Sub New ( _
color As Color, _
width As Single _
)
'Usage
Dim color As Color
Dim width As Single
Dim instance As New Pen(color, width)
public Pen (
Color color,
float width
)
public:
Pen (
Color color,
float width
)
public Pen (
Color color,
float width
)
public function Pen (
color : Color,
width : float
)
Parameter
- width
Ein Wert, der die Breite dieses Pen angibt.
Hinweise
Die Color-Eigenschaft wird auf die vom color-Parameter angegebene Farbe festgelegt. Die Width-Eigenschaft wird auf den im width-Parameter angegebenen Wert festgelegt. Das Zeichnen mit dem Pen bei einer width von 0 entspricht dem bei einer Breite von 1.
Beispiel
Im folgenden Codebeispiel werden das Erstellen eines Pen und die Auswirkungen des Festlegens der DashCap-Eigenschaft, der DashPattern-Eigenschaft und der SmoothingMode-Eigenschaft veranschaulicht.
Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Fügen Sie den Code in ein Formular ein, und rufen Sie beim Behandeln des Paint-Ereignisses des Formulars die ShowPensAndSmoothingMode-Methode auf, wobei Sie e als PaintEventArgs übergeben.
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
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:
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.get_Graphics().set_SmoothingMode(
System.Drawing.Drawing2D.SmoothingMode.AntiAlias);
// Create a new Pen object.
Pen greenPen = new Pen(Color.get_Green());
// Set the width to 6.
greenPen.set_Width(6);
// Set the DashCap to round.
greenPen.set_DashCap(System.Drawing.Drawing2D.DashCap.Round);
// Create a custom dash pattern.
greenPen.set_DashPattern(new float[] { 4, 2, 1, 3 });
// Draw a line.
e.get_Graphics().DrawLine(greenPen, 20, 20, 100, 240);
// Change the SmoothingMode to none.
e.get_Graphics().set_SmoothingMode(
System.Drawing.Drawing2D.SmoothingMode.None);
// Draw another line.
e.get_Graphics().DrawLine(greenPen, 100, 240, 160, 20);
// Dispose of the custom pen.
greenPen.Dispose();
} //ShowPensAndSmoothingMode
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0