The widen method of the path can convert the line in the path into a range (a bit similar to the area) based on the width and style of the specified paint brush ); however, after the conversion, you can only use fillpath instead of drawpath to depict the path. in this example, two default parameters are not tested, because we have already mentioned these parameters.
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) checkbox1: tcheckbox; checkbox2: tcheckbox; procedure alert (Sender: tobject); Procedure checkbox1click (Sender: tobject); Procedure checkbox2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; Procedure tform1.formcreate (Sender: tobject); begin checkbox1.caption: = 'execute widen '; checkbox2.caption: = 'show all vertices in the path'; end; procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; P: tgppen; B1, B2: tgpbrush; Path: tgpgraphicspath; PTS: array of tgppoint; I: integer; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (aclslategray, 20); p. setendcap (linecaparrowanchor); B1: = tgpsolidbrush. create (aclred); B2: = tgphatchbrush. create (hatchstylediagonalcross, aclsilver, aclslategray); Path: = tgpgraphicspath. create; Path. addline (40, 50, ClientWidth-40, 50); If checkbox1.checked then begin path. widen (p); G. fillpath (B2, PATH); End else G. drawpath (p, PATH); If checkbox2.checked then begin setlength (PTS, path. getpointcount); Path. getpathpoints (pgppoint (PTS), length (PTS); tgpsolidbrush (B1 ). setcolor (aclred); for I: = 0 to length (PTS)-1 do G. fillrectangle (B1, PTS [I]. x-3 (PTS [I]. y-3, 6, 6); end; Path. free; b1.free; b2.free; p. free; G. free; end; Procedure tform1.checkbox1click (Sender: tobject); begin repaint; end; Procedure tform1.checkbox2click (Sender: tobject); begin repaint; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 136 clientwidth = 287 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = pow.topcenter oncreate = formcreate onpaint = formpaint pixelsperinch = 96 textheight = 13 object checkbox1: tcheckbox left = 43 Top = 104 width = 97 Height = 17 caption = 'checkbox1' taborder = 0 onclick = checkbox1click end object checkbox2: tcheckbox left = 138 Top = 104 width = 125 Height = 17 caption = 'checkbox2 'taborder = 1 onclick = checkbox2click endend