动态生成TIMage时的问题,请大家帮忙看看问题在那里!

cxfirefox 2003-07-26 11:39:40
我在动态生成图像的时候,有时候点击一下会出来好几个图像,这是什么原因呢?代码如下:
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;
...全文
36 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxfirefox 2003-07-27
  • 打赏
  • 举报
回复
现在的主要问题就是有时候点击ImgDrawingPad一次,会出现多个im,为什么会这样呢?
chinalian 2003-07-26
  • 打赏
  • 举报
回复
加上一句 ImgDrawingPad.canvas.Pen.Mode := pmNotXor;
cxfirefox 2003-07-26
  • 打赏
  • 举报
回复
procedure TForm1.DrawToImage(TL,BR:TPoint;PenMode:TPenMode);事件是在ImgDrawingPad中触发!

procedure TForm1.ImgDrawingPadMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
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;
FrameSniper 2003-07-26
  • 打赏
  • 举报
回复
使用Assigned函数来控制Img对象的创建是唯一的.......
FrameSniper 2003-07-26
  • 打赏
  • 举报
回复
不明白楼主的第一个事件在什么时候可以触发

既然会出现多个图象,就说明第一个事件被多次触发,而且PenMode参数始终是dtRoundREct。因此,个人认为不应该把对Img的创建过程放在那个Case的分支中,至于放哪里,楼主自己定了....

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧