Draw lines that are striped lengthwise in C#

The Pen class's CompoundArray property stores an array of floats that gives the fraction of the line's width that is drawn and skipped. For example, the array 0.0, 0.25, 0.75, 1.0 means draw the first 25% of the line's width, skip to 75% of the way through, and then draw the last 25% of the line. The result is a line with a clear stripe down the middle.

This example uses the following code to draw a line that has two thin clear strips near its edges.

// Draw with a compound pen.
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

using (Pen the_pen = new Pen(Color.Blue, 20))
{
the_pen.CompoundArray =
new float[] { 0.0f, 0.1f, 0.2f, 0.8f, 0.9f, 1.0f };

// Make points to define a star.
Rectangle rect = new Rectangle(30, 30,
this.ClientSize.Width - 60,
this.ClientSize.Height - 40);
PointF[] pts = StarPoints(5, rect);

e.Graphics.DrawPolygon(the_pen, pts);
}
}

See the example Draw a star in C# to learn how the StarPoints function works.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.