// Wonderful exclusive or operations.Code, Repeatedly click the button... procedure tform1.button1click (Sender: tobject); begin canvas. pen. color: = clyellow; {specify the pen color as yellow} canvas. pen. width: = 20; {pen width 20} canvas. pen. mode: = pmxor; {specify the paint brush mode as: exclusive or operation between the paint brush color and the background color} {draw line} canvas. moveTo (0, 0); canvas. lineto (clientwidth, clientheight); end;
//:
// Example of creating a rubber line: Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) 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} var X1, Y1, X2, Y2: integer; {coordinate of two endpoints of a straight line} f: Boolean; {determine if the mouse is down} procedure tform1.formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin X1: = x; Y1: = y; X2: = x; Y2: = y; canvas. pen. color: = clred; canvas. pen. width: = 2; canvas. pen. mode: = pmxor; F: = true; end; Procedure tform1.formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); begin if F then begin {erased} canvas. moveTo (x1, Y1); canvas. lineto (X2, Y2); X2: = x; Y2: = y; {redraw} canvas. moveTo (x1, Y1); canvas. lineto (X2, Y2); end; Procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer ); begin if F then begin {draw a definite line} canvas. pen. mode: = pmcopy; canvas. moveTo (x1, Y1); canvas. lineto (X2, Y2); F: = not F; end.
//: