Learn more about GDI + [14]: drawbeziers-draw a group of besels

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

  

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.