This example mainly uses the mouse to draw on the form
Components available with Tbevel, Tradiogroup, TButton components
The results are as follows:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Extctrls, Stdctrls , Xpman;typeTForm1=class(tform) bevel1:tbevel; Bevel2:tbevel; Bevel3:tbevel; Bevel4:tbevel; Button1:tbutton; Radiogroup1:tradiogroup; Button2:tbutton; procedureFormmousedown (sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer); procedureFormmousemove (sender:tobject; Shift:tshiftstate; X, Y:integer); procedureFormmouseup (sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer); procedureButton1Click (Sender:tobject); procedureButton2click (Sender:tobject); PrivateStart:boolean; Ox,oy:integer; {Private Declarations} Public {Public Declarations} End;varForm1:tform1;Implementation{$R *.DFM}procedureTform1.formmousedown (sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);beginStart:=true; CaseRadiogroup1.itemindex of 0: ; // Nothing1,2,3,4, 5:beginOX:=X; OY:=Y; End; End; Self.Canvas.MoveTo (x, y); / /Set the starting position of the brushEnd;procedureTform1.formmousemove (sender:tobject; Shift:tshiftstate; X, Y:integer);begin ifStart Then begin CaseRadiogroup1.itemindex of//operation according to the index number of the Tradiogroup component 0:beginCanvas.Pen.Color:=Clwindowtext; //Set the brush to black self. Canvas.lineto (x, y); //Draw lines on the form while the mouse is moving End; 1,2,3,4: Canvas.Pen.Color: = Clwindowtext;//Set brush to black5:beginCanvas.Pen.Color:=Form1. Color; //Set brush color to form color Canvas.Brush.Color:=Form1. Color; //Set brush color to form color Canvas.rectangle (X-2, Y2, x+2, y+2); //Erase a form End; End; End;End;procedureTform1.formmouseup (sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);beginStart:=false; CaseRadiogroup1.itemindex of 0: ; 1: Canvas.arc (ox,oy,x,y,ox,oy,x,y); //Draw arcs 2: Canvas.ellipse (Rect (ox,oy,x,y)); //Draw ellipse 3: Canvas.rectangle (ox,oy,x,y); //Draw Rectangle 4:begin //Draw ellipse ifABS (X-ox) <abs (Y-oy) ThenCanvas.ellipse (Ox,oy,ox+abs (Ox-x), Oy+abs (ox-x) //Draw an ellipse at the length of the X value ElseCanvas.ellipse (Ox,oy,ox+abs (oy-y), Oy+abs (oy-y)); //Draw an ellipse at the length of the Y value End; End;End;procedureTform1.button2click (sender:tobject);beginClose;End;procedureTform1.button1click (sender:tobject);beginForm1.canvas.FillRect (Rect (9,9,392,288));End;End.
Delphi7 Image Chapter (iii)