Re-learning gdi+[52]: path

Source: Internet
Author: User
Tags reset

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;
var pts:array[0..6] of Tgppoint;
Procedure Tform1.formcreate (Sender:tobject);
Begin
Pts[0]. X: = 10; Pts[0]. Y: = 50;
PTS[1]. X: = 40; PTS[1]. Y: = 90;
PTS[2]. X: = 80; PTS[2]. Y: = 10;
PTS[3]. X: = 110; PTS[3]. Y: = 50;
PTS[4]. X: = 140; PTS[4]. Y: = 10;
PTS[5]. X: = 180; PTS[5]. Y: = 90;
PTS[6]. X: = 210; PTS[6]. Y: = 50;
Checkbox1.caption: = ' Flip the point in the path ';
Checkbox2.caption: = ' Empty the point in the path ';
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
Path:tgpgraphicspath;
Pathpts:array of Tgppoint;
I:integer;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = Tgppen.create (aclred, 2);
Path: = Tgpgraphicspath.create;
Path. AddBeziers (Pgppoint (@pts), Length (pts));
If checkbox1.checked then path. Reverse;
If checkbox2.checked then path. Reset;
{When Reset, the pathpoints and pathtypes arrays are emptied and the Fillmode is set to Fillmodealternate}
SetLength (pathpts, path.) Getpointcount);
Path. Getpathpoints (Pgppoint (pathpts), Length (pathpts));
Canvas.Pen.Color: = Clgray;
For I: = Low (pathpts) to High (pathpts) do
Canvas.textout (Pathpts[i]. X, Pathpts[i]. Y, IntToStr (i+1));
G.drawpath (P, path);
Path. Free;
P.free;
G.free;
End
Procedure Tform1.checkbox1click (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.checkbox2click (Sender:tobject);
Begin
Repaint;
End
End.

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.