试试下面这个:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TPainterThread = class(TThread)<br> private<br> X, Y: Integer;<br> protected<br> procedure Execute; override;<br> procedure Paint;<br> end;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure FormMouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br> private<br> { Private declarations }<br> PT: TPainterThread;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TPainterThread }<br><br>procedure TPainterThread.Execute;<br>begin<br> Randomize;<br> repeat<br> X := Random (300);<br> Y := Random (Form1.ClientHeight);<br> Synchronize (Paint);<br> until Terminated;<br>end;<br>procedure TPainterThread.Paint;<br>begin<br> Form1.Canvas.Pixels [X, Y] := clRed;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> Button1.Enabled := False;<br> Button2.Enabled := True;<br> PT := TPainterThread.Create (False); // 开始<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> PT.Free;<br> Button1.Enabled := True;<br> Button2.Enabled := False;<br>end;<br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br> Shift: TShiftState; X, Y: Integer);<br>begin<br> ShowMessage('Test');<br>end;<br>end.