Re-learning gdi+[11]: DrawCurve

Source: Internet
Author: User
Tags integer

This example effect chart:

Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Comctrls, Extctrls;
Type
TForm1 = Class (Tform)
Button1:tbutton;
Trackbar1:ttrackbar;
Labelededit1:tlabelededit;
Labelededit2:tlabelededit;
Procedure Formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Procedure Formpaint (Sender:tobject);
Procedure Formcreate (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Trackbar1change (Sender:tobject);
Procedure Labelededit1change (Sender:tobject);
Procedure Labelededit2change (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
Ptarr:array of Tgppoint;
I:integer = 0;
Tension:single;
Procedure Tform1.formcreate (Sender:tobject);
Begin
Button1.caption: = ' erase ';
LabeledEdit1.EditLabel.Caption: = ' starting point ';
LabeledEdit2.EditLabel.Caption: = ' valid points ';
Labelededit1.text: = ' 0 ';
Labelededit2.text: = ' 0 ';
Trackbar1.showselrange: = False;
Trackbar1.min: =-25;
Trackbar1.max: = 35;
Trackbar1.position: = 5;
End
Procedure Tform1.formmouseup (Sender:tobject; Button:tmousebutton;
Shift:tshiftstate; X, Y:integer);
Begin
INC (i);
SetLength (Ptarr, i);
PTARR[I-1]. x: = x;
PTARR[I-1]. Y: = y;
Labelededit2.text: = IntToStr (i-1);
Text: = IntToStr (i);
Repaint;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
I,n1,n2:integer;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = Tgppen.create (aclred, 2);
G.clear (Aclwhite);
N1: = Strtointdef (labelededit1.text, 0);
N2: = Strtointdef (Labelededit2.text, Length (Ptarr)-1);
{The following three parameters are optional, the default value for the last parameter is 0.5, and the 0 o'clock curve is converted to a straight line segment}
G.drawcurve (P, Pgppoint (Ptarr), Length (Ptarr), N1, N2, tension);
P.setwidth (1);
P.setcolor (Aclblack);
For I: = 0 to Length (ptarr)-1 do
G.drawellipse (P, ptarr[i]. X-2, Ptarr[i]. Y-2, 4, 4);
G.free;
P.free;
End
Procedure Tform1.labelededit1change (Sender:tobject);
Var
A,b:integer;
Begin
A: = Strtointdef (labelededit1.text, 0);
if (a < 0) or (A > Length (Ptarr)-2) Then
Labelededit1.text: = IntToStr (0);
A: = Strtointdef (labelededit1.text, 0);
B: = Strtointdef (labelededit2.text, 0);
If A+b > Length (Ptarr)-1 Then
Labelededit2.text: = IntToStr (Length (Ptarr) -1-a);
Repaint;
End
Procedure Tform1.labelededit2change (Sender:tobject);
Var
A,b:integer;
Begin
A: = Strtointdef (labelededit1.text, 0);
B: = Strtointdef (labelededit2.text, 0);
if (b < 0) or (b >= Length (Ptarr)-a) then
Labelededit2.text: = IntToStr (Length (Ptarr) -1-a);
Repaint;
End
Procedure Tform1.trackbar1change (Sender:tobject);
Begin
Tension: = TRACKBAR1.POSITION/10;
Repaint;
End
Procedure Tform1.button1click (Sender:tobject);
Begin
I: = 0;
SetLength (Ptarr, i);
Repaint;
Text: = IntToStr (i);
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.