以下程序在Image上画线,按右键清除.<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Image1: TImage;<br> procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br> procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br> Y: Integer);<br> procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> Draw :Boolean;<br> p1,p2 :TPoint;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>begin<br> if Button=mbLeft then<br> begin<br> Draw :=True;<br> p1 :=Point(x,y);<br> p2 :=Point(x,y);<br> end;<br> if Button=mbRight then<br> begin<br> Image1.Canvas.MoveTo(p1.x,p1.y);<br> Image1.Canvas.LineTo(p2.x,p2.y);<br> end;<br>end;<br><br>procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br> Y: Integer);<br>begin<br> if Draw then<br> begin<br> Image1.Canvas.Pen.Mode :=pmNotXor;<br> Image1.Canvas.MoveTo(p1.x,p1.y);<br> Image1.Canvas.LineTo(p2.x,p2.y);<br> p2 :=Point(x,y);<br> Image1.Canvas.MoveTo(p1.x,p1.y);<br> Image1.Canvas.LineTo(p2.x,p2.y);<br> end;<br>end;<br><br>procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>begin<br> if Draw then<br> begin<br> Image1.Canvas.MoveTo(p1.x,p1.y);<br> Image1.Canvas.LineTo(p2.x,p2.y);<br> p2 :=Point(x,y);<br> Image1.Canvas.MoveTo(p1.x,p1.y);<br> Image1.Canvas.LineTo(p2.x,p2.y);<br> Draw :=False;<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> Draw :=False;<br>end;<br><br>end.<br>