Delphi's plotting function [12]-tpen class (lower): learning the rubber line

Source: Internet
Author: User
// 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.
 
   
 //:


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.