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 formcreate (Sender: tobject); Procedure formdestroy (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 ); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; var X: integer = 20; Y: integer = 20; W: integer = 100; H: integer = 50; F: byte; A, B: integer; P: tgppen; Procedure tform1.formcreate (Sender: tobject); begin P: = tgppen. create (makecolor (255, 0, 0), 2); end; Procedure tform1.formdestroy (Sender: tobject); begin p. free; end; Procedure tform1.formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin F: = 1; A: = x; B: = y; end; Procedure tform1.formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); begin if (F = 0) Then exit; if ssctrl in shift then begin F: = 2; text: = 'ctrl: Press, the mouse can resize '; end else text: =' No ctrl key pressed, the mouse can adjust the position '; A: = x-A; B: = Y-B; repaint; A: = x; B: = y; end; Procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin F: = 0; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; begin G: = tgpgraphics. create (canvas. handle); G. clear (makecolor (255,255,255); Case F of 1: Begin Inc (X, A); Inc (Y, B); end; 2: Begin Inc (W, ); INC (H, B); end; G. drawellipse (p, X, Y, W, H); G. free; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 176 clientwidth = 337 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter oncreate = formcreate ondestroy = formdestroy onmousedown = formmousedown onmousemove = formmousemove onmouseup = formmouseup onpaint = formpaint placement = 96 textheight