我在动态生成图像的时候,有时候点击一下会出来好几个图像,这是什么原因呢?代码如下:
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;
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;
解决方案 »
- 求图像定位放大算法
- 一个困扰我多年的问题:怎么知道别人的程序中都用的什么控件?
- 怎样让自己写的程序随系统的启动而运行
- 有关fastreport的问题
- 用listview将远程文件列出来,知道这个文件名排在第二个位置,怎样将这个文件的文件名取出来?
- 如何作出象QQ一样可以自动隐藏鼠标滑入立即弹出显示
- 本年最后一次.............前10位反馈者散分!!
- 大家好>我想请教SQL SERVER为什么非要使用ODBC才能连接
- 求救,送分!!
- CSDN的兄弟们,我只有20分了,这次出15分,给点建议?C/S?两层?三层?
- 新手上路,请高手多照应!我想做一个很简单的COMPONENT!
- 求Delphi电子书
begin
if Drawing then
begin
if DrawType=dtCrooked then
begin
ImgDrawingpad.Canvas.MoveTo(LastDot.X,LastDot.Y);
ImgDrawingpad.Canvas.LineTo(X,Y);
LastDot:=Point(X,Y);
end
else begin
DrawToImage(MOuseOrg,NextPoint,pmNotXor);
NextPOint:=POint(x,y);
DrawToImage(MouseOrg,NextPoint,pmNotXor);
end;
end;
stbMain.Panels[1].Text:=Format('X: %d,Y: %d',[x,y]);
end;procedure TForm1.ImgDrawingPadMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Drawing then
if not(DrawType=dtClipRect) then
DrawToImage(MouseOrg,Point(x,y),pmCOpy);
Drawing:=false;
end;