动态生成TIMage时的问题,请大家帮忙看看问题在那里!
我在动态生成图像的时候,有时候点击一下会出来好几个图像,这是什么原因呢?代码如下:
procedure TForm1.DrawToImage(TL,BR:TPoint;PenMode:TPenMode);
var im:TImage;begin
with ImgDrawingPad.Canvas do //ImgDrawingPad:TIMage
begin
Pen.Mode:=PenMode;
{DrawType=Calss(TDRawTpye);TDrawType(dtLIneDraw..dtClipREct)}
case DrawType of
dtLineDraw :begin
MoveTo(TL.X,Tl.Y);LineTo(Br.X,BR.Y);Screen.cursor:=crDefault;
end ;
dtRectangle :Rectangle(Tl.X,tl.Y,Br.X,br.Y) ;
dtEllipse :begin Screen.cursor:=crDefault;Ellipse(Tl.X,tl.Y,Br.X,Br.Y);end;
dtRoundREct:begin
Screen.cursor:=crDefault;
im:=TImage.Create(self) ;
im.Parent:=sbxMain;
im.AutoSize:=true;
im.Stretch:=true;
im.Picture.LoadFromFile('E:\Program Files\Borland\Delphi6\Projects\CxApp\»Í¼\R.Bmp');
im.Left:=200;
im.Top:=200;
im.Visible:=true;
imExist:=true;
im.OnMouseDown:=form1.ImgMouseDown;
im.OnMouseMove:=form1.ImgMouseMove;
im.OnMouseUp:=form1.ImgMouseUp;
end;
dtClipRect: begin Screen.cursor:=crDefault;Rectangle(Tl.X,tl.Y,br.x,br.y);end;
end;
end;
end;
procedure TForm1.ImgMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssleft in Shift then begin
modified:=true;
X1:=X;Y1:=Y;
ImgMoving:=true;
end;
end;
procedure TForm1.ImgMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ImgMoving:=false;
end;
procedure TForm1.ImgMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ImgMoving=true then begin
(Sender as TIMage).Left:=(Sender as TIMage).Left+X-x1;
(sender as TImage).Top:=(Sender as TImage).Top+Y-Y1;
end;
end;