Re-learning gdi+[14]: drawbeziers

Source: Internet
Author: User
Tags integer

This example effect chart:

Code files:Unit Unit1;
Interface
Uses
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: = ' Hold CTRL key to add point ';
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
End
End
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);
{When points are 3*n+1}
If Length (pts) MoD 3 = 1 then Repaint;
End
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 = 13
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.