还是画图问题,请大家帮助!

cxfirefox 2003-07-25 09:29:47
在画图中,我有一个SpeedButton,点击之后在画布上MouseDown就能显示一个自定义的图形(动态生成),但是为了拖动这个图形,我又定义了它的OnMouseDown属性,结果会产生意想不到的结果,那么为了解决这个问题,我需要再设置一个选择按钮,点击之后再拖动这个图形就不会产生问题,诸位有没有什么意见呢?
...全文
60 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wooden954 2003-07-26
  • 打赏
  • 举报
回复
拿代码出来看看才能帮你解决呀!没有代码,谁也不会知道你的鼠标事件是怎么相互干扰的
cxfirefox 2003-07-26
  • 打赏
  • 举报
回复
功能是实现了,就是这两个鼠标事件老是相互干扰,本来想拖动这个图像,谁知道无形之中又生成了一个图像,怎么才能让他们不相互干涉呢?
cxfirefox 2003-07-26
  • 打赏
  • 举报
回复
代码如下:
procedure TForm1.ImgDrawingPadMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Modified:=True;
if (DRawType=dtClipRect) and EraseClipRect then
DrawToImage(MOuseOrg,NextPoint,pmNotXor)//??
else if (DrawType=dtClipRect) then
EraseClipREct:=true;
if pasted then
CopyPasteBOxToImage;
Drawing:=true;
MouseOrg:=Point(x,y);
NextPoint:=MOuseOrg;
LastDot:=NextPoint;
ImgDrawingPad.Canvas.MoveTo(X,Y);
end;

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.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;
李_军 2003-07-25
  • 打赏
  • 举报
回复
能实现功能就行

5,388

社区成员

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

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