In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formpaint (Sender: tobject ); procedure formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); Procedure formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer ); procedure formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); Procedure formcreate (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; var PTS: array of tgppoint; PTN: integer =-1; F: Boolean; Procedure tform1.formcreate (Sender: tobject); begin text: = 'Press CTRL to add a vertex '; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; P: tgppen; I: integer; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (aclred, 1); G. clear (aclwhite); G. drawbeziers (p, pgppoint (PTS), length (PTS); p. setcolor (aclblue); for I: = low (PTS) to high (PTS) DO G. drawrectangle (p, makerect (rect (PTS [I]. x-2 (PTS [I]. y-2 (PTS [I]. X + 2, PTS [I]. Y + 2); G. free; p. free; end; Procedure tform1.formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin F: = true; end; Procedure tform1.formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); var R: trect; I: integer; begin if F then begin if PTN =-1 then exit; PTS [PTN]. x: = x; PTS [PTN]. y: = y; repaint; end else begin PTN: =-1; cursor: = crdefault; for I: = low (PTS) to high (PTS) do Begin R: = rect (PTS [I]. x-2 (PTS [I]. y-2 (PTS [I]. X + 2, PTS [I]. Y + 2); If ptinrect (R, point (x, y) then begin PTN: = I; cursor: = crhandpoint; end; procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin F: = false; If ssctrl in shift then begin setlength (PTS, length (PTS) + 1); PTS [high (PTS)]. x: = x; PTS [high (PTS)]. y: = y; canvas. pen. color: = clblue; canvas. rectangle (X-2, Y-2, x + 2, Y + 2); {draw again when points are 3 * n + 1} If length (PTS) mod 3 = 1 then repaint; end; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 188 clientwidth = 254 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter oncreate = formcreate onmousedown = formmousedown onmousemove = formmousemove onmouseup = formmouseup onpaint = formpaint pixelsperinch = 96 textheight = 13end