Learn more about GDI + [11]: drawcurve-draw a curve

Source: Internet
Author: User
In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls, extctrls; Type tform1 = Class (tform) button1: tbutton; trackbar1: ttrackbar; tags: tlabelededit; labelededit2: tlabelededit; Procedure formmouseup (Sender: tobject; button: tmousebutton; shift: cursor; X, Y: integer); Procedure formpaint: tobject); Procedure future (Sender: tobject); Procedure trackbar1change (Sender: tobject); Procedure future (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: = 'start'; labelededit2.editlabel. caption: = 'valid point'; 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 of the last parameter is 0.5. When the value is 0, the 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 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: = strtointdef (labelededit1.text, 0); B: = strtointdef (labelededit2.text, 0); If (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.
 
   
 

Form file:

Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 187 clientwidth = 264 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = pow.topcenter oncreate = formcreate onmouseup = formmouseup onpaint = formpaint pixelsperinch = 96 textheight = 13 object button1: tbutton left = 181 Top = 155 width = 75 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object trackbar1: ttrackbar left = 8 Top = 155 width = 167 Height = 25 taborder = 1 onchange = trackbar1change end object labelededit1: tlabelededit left = 208 Top = 54 width = 48 Height = 21 editlabel. width = 61 editlabel. height = 13 editlabel. caption = 'labelededit1' taborder = 2 onchange = labelededit1change end object labelededit2: tlabelededit left = 208 Top = 102 width = 48 Height = 21 editlabel. width = 61 editlabel. height = 13 editlabel. caption = 'labelededit2' taborder = 3 onchange = labelededit2change endend
 
  
 

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.