修改了一下程序,下面的示例可实现你要的功能,额外开销是一个TImage和一个TPanel,也可在程序中创建,应该不算太浪费资源罢?
主要思路是,用一个TImage和一个TPanel来模拟自己创建的Image的移动过程:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ExtDlgs;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
procedure MDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Panel1.Left := (Sender as TImage).Left;
Panel1.Top := (Sender as TImage).Top;
Panel1.Width := (Sender as TImage).Width;
Panel1.Height := (Sender as TImage).Height;
Image1.Picture.Bitmap := (Sender as TImage).Picture.Bitmap;
ReleaseCapture;
Panel1.Perform(WM_SYSCOMMAND,$F012,0);
(Sender as TImage).Left := Panel1.Left;
(Sender as TImage).Top := Panel1.Top;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
img:TImage;
FN :string;
begin
if OpenPictureDialog1.Execute then
FN := OpenPictureDialog1.FileName
else FN := 'c:/a.bmp';
img := TImage.Create(self);
img.Picture.LoadFromFile(FN);
img.AutoSize := True;
img.OnMouseDown := Form1.MDown;
Form1.InsertControl(img);
end;
end.
唉,搵食艰难啊... ...