怎样移动让程序运行时控件?(200分)

  • 主题发起人 主题发起人 qf0421
  • 开始时间 开始时间
我把问题提提前。

 
每一个TIMAGE都放一个TPANEL,这岂不是太浪费资源?
 
每一个TIMAGE都放一个TPANEL,这岂不是太浪费资源?

 
每一个TIMAGE都放一个TPANEL,这岂不是太浪费资源?
 
修改了一下程序,下面的示例可实现你要的功能,额外开销是一个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.

唉,搵食艰难啊... ...
 
多人接受答案了。
 
后退
顶部