Biker back Parker-several details of drawing a line on graphics using a pen

Source: Internet
Author: User
Tags linecap

Biker and Parker

Refer:

"10 basic techniques for GDI + programming"

"Rubber band"

Draw dotted lines on the canvas with a pen

To draw the dotted line and the geometric shape of the dotted line border on the graphics object, the key is all on the pen object.

Pen. dashstyle -- used to set the dotted line style. This property receives a dashstyle enumeration.

Dash

Draw line

Dashdot

Click to draw a line

Dashdotdot

Point-to-Point

Dot

Point

Solid

Solid line

Custom

User-Defined line type

Protected override void onpaint (painteventargs E)

{

Base. onpaint (E );

Pen P = new pen (color. Red );

P. dashstyle = dashstyle. Dash;

E. Graphics. drawline (p, new point (10, 10), new point (300,300 ));

}

Pen. dashcap -- specifies the line-to-phase style of the end point of a dashcap. This property accepts a dash enumeration.

Flat

Both ends are square.

Round

Both ends are rounded circles.

Triangle

Both ends are triangular.

Protected override void onpaint (painteventargs E)

{

Base. onpaint (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, 20366f, 20366f, 100366f, 240.0f );

// Change the smoothingmode to none.

E. Graphics. smoothingmode =

System. Drawing. drawing2d. smoothingmode. None;

// Draw another line.

E. Graphics. drawline (greenpen, 100366f, 240.0f, 160.0f, 20366f );

// Dispose of the custom pen.

Greenpen. Dispose ();

}

Pen. dashoffset -- the distance from the starting point of a straight line to the starting point of a dash.

Pen. dashpattern -- an array of custom dashes and blank areas.

Draw arrows on a straight line

Pen. startcap -- the line-to-phase style at the starting point of a straight line.

Pen. endcap -- the line-to-phase style of the end point of a straight line.

Both attributes are subject to linecap enumeration.

Protected override void onpaint (painteventargs E)

{

Base. onpaint (E );

Pen P = new pen (color. Red );

P. width = 20;

P. startcap = linecap. roundanchor;

P. endcap = linecap. diamondanchor;

E. Graphics. drawline (p, 50, 50,250,250 );

}

Pen. customstartcap -- specifies the starting line and phase style of the custom line segment.

Pen. customendcap -- custom line section finish line style.

These two attributes accept the customlinecap object.

Protected override void onpaint (painteventargs E)

{

Base. onpaint (E );

Graphicspath hpath = new graphicspath ();

// Create the outline for our custom end cap.

Hpath. addline (new point (0, 0), new point (0, 5 ));

Hpath. addline (new point (0, 5), new point (5, 1 ));

Hpath. addline (new point (5, 1), new point (3, 1 ));

// Construct the hook-shaped end cap.

Customlinecap hookcap = new customlinecap (null, hpath );

// Set the start cap and end cap of the hookcap to be rounded.

Hookcap. setstrokecaps (linecap. Round, linecap. Round );

// Create a pen and set end custom start and end

// Caps to the hook cap.

Pen customcappen = new pen (color. Black, 5 );

Customcappen. customstartcap = hookcap;

Customcappen. customendcap = hookcap;

// Create a second pen using the start and end caps from

// The Hook cap.

Pen cappen = new pen (color. Red, 10 );

Linecap startcap;

Linecap endcap;

Hookcap. getstrokecaps (Out startcap, out endcap );

Cappen. startcap = startcap;

Cappen. endcap = endcap;

// Create a line to draw.

Point [] points = {New Point (100,100), new point (200, 50 ),

New Point (250,300 )};

// Draw the lines.

E. Graphics. drawlines (cappen, points );

E. Graphics. drawlines (mcmcappen, points );

}

Refer:

"10 basic techniques for GDI + programming"

"Rubber band"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.