(6) Regional graphics Form Create a new Form1, saved as Capture1.PAS. Setting the four properties of the properties Bordericons Set to BSNONE.Borderstyle Set to Cross, formorle is set to fsstayontop. Add a private variable: fdragging: boolean; two common variables: FRECT: TRECT, FBMP: Tbitmap; Form1 role : Create when the area grabs, and disappears after graphic.
Unit Capture1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs
type TForm1 = class (TForm) procedure FormCreate (Sender: TObject); procedure FormDestroy (Sender: TObject); 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); private fDragging: Boolean; public fRect : TRECT; FBMP: TBITMAP;
Var Form1: TFORM1;
IMPLEMentation
{$ R * .dfm}
Procedure TForm1.FormCreate (Sender: TOBJECT); VAR ADC: HDC; // Device Description Table Handle Begin FBmp: = Tbitmap.create; fbmp.Width: = Screen.Width; fbmp.height: = Screen.Height; adc: = GetDC (0); // Get the handle of the device descriptor table of a window, 0 Parameters Return to the screen window device Descript Table of the handle Bitblt (fbmp.canvas.handle, 0, 0, screen.width, Screen.Height, ADC, 0, 0, SRCCOPY; ReleaseDC (0, ADC,); SetBounds (0, 0, Screen.Width, Screen.Height); END;
Procedure TFORM1.FORMDESTROY (Sender: TOBJECT); begin fbmp.free; end;
Procedure TForm1.FormPaint (Sender: TOBJECT); Begin Canvas.draw (0, 0, FBMP); // Draw graphics to Canvasend;
// If you press the left mouse button, set the rectangular FRECT with SetRect so that it is just a point. // use painted rectangle DrawFocusRect this procedure TForm1.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then begin fDragging: = true; SetRect (fRect, x , Y, X, Y); END; END; // When the mouse moves, it is determined whether or not it is in the drawing (left mouse button down), DrawFocusRect reset the rectangle // Make the lower right corner as the current mouse position, draw the rectangle DrawFocusRect calling procedure TForm1.FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if fDragging then begin Canvas.DrawFocusRect (fRect); fRect.Right: = X; fRect.Bottom : = Y; Canvas.drawFocusRect (FRECT); END;
/ / Judgment whether or not in the drawing (left mouse button), the mouse bounces, // DrawFocusRect Reset the rectangle. Close Form Procedure TFORM1.FORMMMOMMOUSEUP (Sender: Tobject; Button: tmousebutton; shift: TshiftState; x, y : Integer; begin if fdragging The begin canvas.drawfocusRect (FDRAGGING: = FALSE; END; MODALRESULT: = mrok; // Turns the form end;
End.