Tag Archives: draw lines

Let the user draw lines in C#

This example lets the user click and draw to draw lines. To make working with lines easier, the program uses the following Segment class. class Segment { public Pen Pen; public Point Point1, Point2; public Segment(Pen pen, Point point1, Point … Continue reading

Posted in drawing, events, graphics | Tagged , , , , , , , , , , , | Leave a comment

Draw a curve with more sharply delineated colors in C#

In the post Draw a curve with sharply delineated colors in C# I mentioned that you could achieve even more sharply defined colors if you use a TextureBrush. Naturally I couldn’t let it reset so here’s an example that does … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , , , , | 1 Comment

Draw a curve with sharply delineated colors in C#

The post Draw a curve with multiple colors in C# shows how you can draw a curve that shades gradually from one color to another as the curve’s Y coordinates change. However, you might not always want the colors to … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , , , , | Leave a comment

Draw a curve with multiple colors in C#

It’s easy enough to draw different lines with different colors but it’s not as easy to draw a single line that uses multiple colors. One way to accomplish that is to make a LinearGradientBrush that defines the colors that you … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , , , , | 1 Comment

Print at full scale in C#

This example shows how you can print at full scale so objects drawn on the screen are the same size when printed. Note that your screen and printer are probably not calibrated exactly so the result will not match perfectly. … Continue reading

Posted in drawing, GDI+, graphics, printing | Tagged , , , , , , , , , , , , , , , , | 2 Comments

Draw lines with custom end caps in C#

This example shows how you can add custom end caps to lines. When you use a Pen object to draw lines and curves, you can set its CustomStartCap and CustomEndCap properties to determine how the ends of the line are … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , | Leave a comment

Draw lines with end caps in C#

The Pen class’s StartCap and EndCap properties determine how a line draws its end caps. This example uses the following code to draw samples of the predefined end caps. private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(BackColor); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , | Leave a comment

Draw lines with custom dash patterns in C#

To create lines with custom dash patterns, first create a Pen object and set its DashStyle property to Custom. Then set its DashPattern property to an array of floating point numbers that indicate how many units to draw and then … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , | 1 Comment

Draw striped lines in C#

You can use the Pen class to draw striped lines. That 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 … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , | Leave a comment