本光盘是《Delphi 7应用教程》一书的配套光盘
源代码在线查看: unit1.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Var
PaintNow:Boolean;
X1,Y1:integer;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Pen.Width :=5;
Canvas.Pen.Color :=ClBlue;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PaintNow:=True;
x1:=x;
y1:=y;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PaintNow:=False;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
If paintNow then
begin
Canvas.moveto(x1,y1);
Canvas.LineTo(x,y);
end;
x1:=x;y1:=y;
end;
end.