image的移动的问题,请高手指点!!(50分)

  • 主题发起人 主题发起人 jianguo_bu
  • 开始时间 开始时间
J

jianguo_bu

Unregistered / Unconfirmed
GUEST, unregistred user!
我照抄本坛的贴子的代码运行后,但iamge移动不了,请问为什么?
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Image1: TImage;
Panel1: TPanel;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
MouseDownPoint :TPoint;
IsMouseDown :Boolean=False;


implementation

{$R *.dfm}

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
// showmessage('asdf');
if Button=mbLeft then
begin
IsMouseDown :=True;
MouseDownPoint :=Point(x,y);
end;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if IsMouseDown then
begin
caption:=format('[%d,%d]',[image1.top,image1.left]);
if (Image1.Left<=0)and(Image1.Width+Image1.Left>=Panel1.Width) then begin
image1.Left:=Image1.Left+x-MouseDownPoint.x;
if Image1.Left>0 then
Image1.Left:=0;
if Image1.Width+Image1.Left<Panel1.Width then
Image1.Left:=Panel1.Width-Image1.Width;
end;
if (Image1.top<=0)and(Image1.Height+Image1.top>=Panel1.Height) then begin
image1.Top:=Image1.Top+y-MouseDownPoint.y;
if Image1.top>0 then
Image1.Top:=0;
if Image1.Height+Image1.top<Panel1.Height then
Image1.Top:=Panel1.Height-Image1.Height;
end;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsMouseDown :=False;
end;

end.
 
不知道你想达到什么效果,
上面的判断条件可以改变一下
if (Image1.Left<=0)and(Image1.Width+Image1.Left>=Panel1.Width) then begin
改为 if (Image1.Left>=0)and(Image1.Width+Image1.Left<=Panel1.Width) then begin
还有
if (Image1.top<=0)and(Image1.Height+Image1.top>=Panel1.Height) then begin
改为
if (Image1.top>=0)and(Image1.Height+Image1.top<=Panel1.Height) then begin
 

Similar threads

I
回复
0
查看
709
import
I
I
回复
0
查看
566
import
I
I
回复
0
查看
672
import
I
后退
顶部