求救高手! ( 积分: 100 )

  • 主题发起人 主题发起人 leoxi82
  • 开始时间 开始时间
L

leoxi82

Unregistered / Unconfirmed
GUEST, unregistred user!
我想请问下,如何移动image里的图片,就想城市地图一样,点下方向键,移动IMAGE里的图片内容,急!!!谢谢!
 
在窗体上放一个ToolBar组件,在ToolBar组件中再放Image组件,Image组件的strech设为false,Image的Autosize设为true,在Image中载入位图。
添加上、下、左、右四个按钮,加入代码,如在向上按钮中加入:
Image1.top:=Image1.top+10; 即可实现。
我已试过,你看可否。
 
我已式过。不行啊
 
[:(]我要移动的是IMAGE的内容,不是IMAGE控件
 
那用canvas做!简单,
 
给你写,给分
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
isdown:boolean;
ABitmap:TBitMap;
dx,dy,ux,uy,cs:integer;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ABitmap:=TBitMap.Create;
ABitmap.Assign(Image1.Picture.Bitmap);
cs:=0;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
dx:= X;
dy:= Y;
isdown:=true;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if isdown then
begin
if cs=0 then
begin
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(x-dx,y-dy,Abitmap);
end
else
begin
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(x+ux-dx,y+uy-dy,Abitmap);
end;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if cs=0 then
begin
ux:=x-dx;
uy:=y-dy;
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(ux,uy,Abitmap);
isdown:=false;
end
else
begin
ux:=x+ux-dx;
uy:=y+uy-dy;
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(ux,uy,Abitmap);
isdown:=false;
end;
inc(cs);
end;

end.
 
不用像清新空气先生那样麻烦,在我的回答中,要把Image的Autosize设为true.
原码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ToolWin, ComCtrls, StdCtrls, jpeg;

type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
Image1: TImage;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
image1.Top:=image1.Top-10;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
image1.Top:=image1.Top+10;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
image1.Left:=image1.Left-10;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
image1.Left:=image1.Left+10;
end;

end.

不行的话,告诉我EMAIL,我把原程序发给你。
我的EMAIL: jinguang@people.com.cn
 
接受答案了.
 
后退
顶部