怎么样可以在Image上拖动显示的图片??图片的分辨率是大于屏幕的!!
解决方案 »
- 求D6各种网络通信的代码
- [文挡]获取PE文件的导出函数列表
- 如何将后台数据库备份到其他计算机或者本地计算机?
- quickReport问题,为什么生成的报表,只显示一行数据。
- 如何判斷一文件是否打開
- 各位大哥大姐你们好,谁有那个关于奥运会火炬的图标?提供一下好吗?我的邮箱:[email protected]
- 初学DELPHI有几个小问题,请各位delphi朋友帮帮忙!(立马给分)
- 请教:在Win2000下使CTRL+ALT+DEL等系统键实效的函数是什么?
- 高分相送,关于fastreport打印问题,怎样才能使打印的表格在每一页都显示字段名称?
- 查询问题
- delphi 中如何使用XML
- 关于mediaplayer控件有几个问题想请教各位大侠!!
Origin : TPoint;
Image_Left: Integer;
Image_Top : Integer;
Visa1 : TPoint;
Visa2 : TPoint;
CanMove : Boolean;procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (Image1.Width <= Panel2.Width) and (Image1.Height <= Panel1.Height) then
begin
CanMove:=false;
exit;
end;
if Button=mbLeft then
begin
Origin.X:= X;
Origin.Y:= Y;
Image_Left:= Image1.Left;
Image_Top := Image1.Top;
Visa1.X:= X-(Image1.Width - Panel1.Width + Image1.Left);
Visa1.y:= Y-(Image1.Height - Panel1.Height + Image1.Top);
Visa2.x:= X-Image1.left;
Visa2.y:= Y-Image1.top;
CanMove:= true;
end;
end;procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (Image1.Width > Panel1.Width) or (Image1.Height > Panel1.Height) then
if CanMove then
begin
if X < Visa1.X then X:= Visa1.X;
if X > Visa2.X then X:= Visa2.X;
if Y < Visa1.Y then Y:= Visa1.Y;
if Y > Visa2.Y then Y:= Visa2.Y;
if Image1.Left <= Panel1.Left then
Image1.Left:= Image_Left+(X-Origin.X);
if Image1.Top <= Panel1.Top then
Image1.Top:= Image_top+(Y-Origin.y);
end;
end;procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
CanMove:=false;
end;这样写不行,Image上的图片不能跟鼠标移动。
Image 上的图片大于 Panel 的尺寸想让 Image 上图片可以跟随鼠标拖动。
我在 Image 上写了:
在 private 定义了:
Origin : TPoint;
Image_Left: Integer;
Image_Top : Integer;
Visa1 : TPoint;
Visa2 : TPoint;
CanMove : Boolean;
procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (Image1.Width <= Panel1.Width) and (Image1.Height <= Panel1.Height) then
begin
CanMove:=false;
exit;
end;
if Button=mbLeft then
begin
Origin.X:= X;
Origin.Y:= Y;
Image_Left:= Image1.Left;
Image_Top := Image1.Top;
Visa1.X:= X-(Image1.Width - Panel1.Width + Image1.Left);
Visa1.y:= Y-(Image1.Height - Panel1.Height + Image1.Top);
Visa2.x:= X-Image1.left;
Visa2.y:= Y-Image1.top;
CanMove:= true;
end;
end;procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (Image1.Width > Panel1.Width) or (Image1.Height > Panel1.Height) then
if CanMove then
begin
if X < Visa1.X then X:= Visa1.X;
if X > Visa2.X then X:= Visa2.X;
if Y < Visa1.Y then Y:= Visa1.Y;
if Y > Visa2.Y then Y:= Visa2.Y;
if Image1.Left <= Panel1.Left then
Image1.Left:= Image_Left+(X-Origin.X);
if Image1.Top <= Panel1.Top then
Image1.Top:= Image_top+(Y-Origin.y);
end;
end;procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
CanMove:=false;
end;这样写不行,Image上的图片不能跟鼠标移动,有谁能帮我一下。
down1:Boolean;//纪录鼠标按下
ox,oy,nx,ny:integer;//ox,oy纪录鼠标按下时的坐标.nx,ny纪录鼠标移动时,当前的坐标procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
down1:true;//鼠标按下
ox:=x;
oy:=y;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if down1 = True then
begin
nx:=x;
ny:=y;
if ox <> nx then
Image1.Left:= Image1.Left + nx - ox
else
if oy <> ny then
Image1.Top:= Image1.Left + ny - oy;
end;
end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
down1:=False;//只要这个条件不成立,Image1就不会随鼠标移动了
end;
procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
// 必须是Image的宽和高都大于Panel?
// 还是(Image1.Width <= Panel1.Width) or (Image1.Height <= Panel1.Height)?
if (Image1.Width <= Panel1.Width) and (Image1.Height <= Panel1.Height) then
begin
CanMove:=false;
exit; // 不是什么好的选择这里这样用让人头晕,用else if button == mbLeft试试。
// 也或者先设置CanMove标致位,如果CanMove为真再用做你doMoveImage的变量准备工作。
end;
if Button=mbLeft then
begin
Origin.X:= X;
Origin.Y:= Y;
Image_Left:= Image1.Left;
Image_Top := Image1.Top;
Visa1.X:= X-(Image1.Left + Image1.Width - Panel1.Width);
Visa1.y:= Y-(Image1.Top + Image1.Height - Panel1.Height);
Visa2.x:= X-Image1.left;
Visa2.y:= Y-Image1.top;
CanMove:= true;
// 看到这里就觉得你在算法没有想清楚的情况下就开始编码,哈哈哈
end;
end;procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
// 这个if比较多余,因为在MouseDown里的时候CanMove为真的情况已经判断过下面这个布尔表达式了,so comment it
// if (Image1.Width > Panel1.Width) or (Image1.Height > Panel1.Height) then
if CanMove then
begin
if X < Visa1.X then X:= Visa1.X;
if X > Visa2.X then X:= Visa2.X;
if Y < Visa1.Y then Y:= Visa1.Y;
if Y > Visa2.Y then Y:= Visa2.Y;
if Image1.Left <= Panel1.Left then
Image1.Left:= Image_Left+(X-Origin.X);
if Image1.Top <= Panel1.Top then
Image1.Top:= Image_top+(Y-Origin.y);
end;
end;procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
CanMove:=false;
end;其实挺简单的一个问题,google找一下多如牛毛,可说难也难,比如你还要考虑操作风格的问题:1、IMAGE随着左键按下后随mouse而移动?那是否要考虑平滑?因为在Image移动的时候整个Image投影到Form上的Region都需要Refresh!那这也有好的方法暂时避开刷新的问题:2、当MouseDown的时候设置标致,在MouseMove的时候在ScrollBox里画虚框(用Frame3D),当MouseUp的时候真正的移动Image对象的坐标。
你给示例代码没有问题,可更希望你能自己想通,因为这是算法的问题,提高会更快些,如果你要代码我可以把自己过去写的给你贴上来。