如果是想做电厂接线图一类的话,放置控件多了不行,会影响执行速度和浪费系统
资源。看看我的问题
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=280805
如果不是见下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
lblPick: Tlabel;
bdrag:boolean;
x1,y1:integer;
newobj_x,newobj_y:integer;
newobj_tag:integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
bdrag:=false;
for i := 0 to 10 do
begin
lblPick:=Tlabel.Create(form1);
lblPick.Parent := form1; //注意将其Parent置为容器(一般为Form)
// lblpick.Picture.LoadFromFile ('../picmove/ufo.bmp');
// lblpick.Stretch :=true;
lblpick.Transparent :=true;
lblPick.Left :=100+50*(i div 25);
lblPick.Top := 100+(i mod 24)*50;
lblPick.Caption := IntToStr(i+1);
lblPick.Hint :=IntToStr(i+1);
lblPick.Tag:=i;
lblPick.ShowHint :=true;
lblPick.OnClick:=Button2Click;
lblpick.OnMouseDown :=Button2MouseDown;
lblpick.OnMouseMove :=Button2MouseMove;
lblpick.OnMouseUp :=Button2MouseUp;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
caption:=TButton(Sender).Caption;
end;
procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
x1:=x;
y1:=y;
bdrag:=true;
caption:=TButton(Sender).Caption;
end;
procedure TForm1.Button2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bdrag then
begin
TButton(Sender).left:=TButton(Sender).left+x-x1;
TButton(Sender).top:=TButton(Sender).top+y-y1;
end;{if}
caption:=TButton(Sender).Caption;
end;
procedure TForm1.Button2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bdrag:=false;
caption:=TButton(Sender).Caption;
end;
end.