Pen::DashPattern Property
Gets or sets an array of custom dashes and spaces.
Assembly: System.Drawing (in System.Drawing.dll)
public: property array<float>^ DashPattern { array<float>^ get(); void set(array<float>^ value); }
Property Value
Type: array<System::Single>^An array of real numbers that specifies the lengths of alternating dashes and spaces in dashed lines.
| Exception | Condition |
|---|---|
| ArgumentException |
Assigning a value other than null to this property will set the DashStyle property for this Pen to Custom.
The elements in the dashArray array set the length of each dash and space in the dash pattern. The first element sets the length of a dash, the second element sets the length of a space, the third element sets the length of a dash, and so on. Consequently, each element should be a non-zero positive number.
The length of each dash and space in the dash pattern is the product of the element value in the array and the width of the Pen.
The following code example demonstrates the effects of setting the DashCap, DashPattern, and SmoothingMode properties.
This example is designed to be used with Windows Forms. 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; }
Available since 1.1