The widen method of a path converts a line in a path, depending on the width and style of the specified brush, to a range (somewhat like a region); But after the conversion, the path can only be used FillPath instead of drawpath. This example does not test its two default parameters because it has been mentioned several times before.
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;
Type
TForm1 = Class (Tform)
Checkbox1:tcheckbox;
Checkbox2:tcheckbox;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (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 points 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 (+, 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
End.