用Paintbox 显示图片,多少个都行 AItem:=TPaintBox.Create(ScrollBox1); AItem.Tag:=AQuery.FieldByName('ID').AsInteger; AItem.Parent:=ScrollBox1; AItem.OnMouseDown:=PaintBox1MouseDown; AItem.OnMouseMove:=PaintBox1MouseMove; AItem.OnMouseUp:=PaintBox1MouseUp; AItem.OnPaint:=PaintBox1Paint; //绘制内容 procedure TFormDoor.PaintBox1Paint(Sender: TObject); Var AItem:TPaintBox; begin If Not(Sender Is TPaintBox) Then Exit; AItem:=Sender As TPaintBox; ImageList2.Draw(AItem.Canvas,10,25,0) end;//鼠标按下 procedure TFormDoor.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Var P:TPoint; begin If Not(Sender Is TPaintBox) Then Exit; CurrentItemM:=TPaintBox(Sender); ScrollBox1.Refresh; MDown:=True; P.X:=X; P.Y:=Y; P:=TPaintBox(Sender).ClientToScreen(P); OldX:=P.X; OldY:=P.Y; end;//移动 procedure TFormDoor.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Var P:TPoint; begin If Not(Sender Is TPaintBox) Then Exit; If Not MDown Then Exit; If Sender<>CurrentItem Then Exit; P.X:=X; P.Y:=Y; P:=TPaintBox(Sender).ClientToScreen(P); TPaintBox(Sender).Left:=TPaintBox(Sender).Left+P.X-OldX; TPaintBox(Sender).Top:=TPaintBox(Sender).Top+P.Y-OldY; OldX:=P.X; OldY:=P.Y; end;//结束移动 procedure TFormDoor.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin If Not(Sender Is TPaintBox) Then Exit; If Not MDown Then Exit; MDown:=False; If Sender<>CurrentItem Then Exit; TPaintBox(Sender).Left:=Round((TPaintBox(Sender).Left / 8))*8; TPaintBox(Sender).Top:=Round((TPaintBox(Sender).Top / 8))*8; //保存位置信息 //显示信息 end;
http://www.codeidea.com/cn/
AItem.Tag:=AQuery.FieldByName('ID').AsInteger;
AItem.Parent:=ScrollBox1;
AItem.OnMouseDown:=PaintBox1MouseDown;
AItem.OnMouseMove:=PaintBox1MouseMove;
AItem.OnMouseUp:=PaintBox1MouseUp;
AItem.OnPaint:=PaintBox1Paint;
//绘制内容
procedure TFormDoor.PaintBox1Paint(Sender: TObject);
Var AItem:TPaintBox;
begin
If Not(Sender Is TPaintBox) Then Exit;
AItem:=Sender As TPaintBox; ImageList2.Draw(AItem.Canvas,10,25,0)
end;//鼠标按下
procedure TFormDoor.PaintBox1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var P:TPoint;
begin
If Not(Sender Is TPaintBox) Then Exit;
CurrentItemM:=TPaintBox(Sender);
ScrollBox1.Refresh; MDown:=True; P.X:=X; P.Y:=Y; P:=TPaintBox(Sender).ClientToScreen(P);
OldX:=P.X;
OldY:=P.Y;
end;//移动
procedure TFormDoor.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
Var P:TPoint;
begin
If Not(Sender Is TPaintBox) Then Exit;
If Not MDown Then Exit;
If Sender<>CurrentItem Then Exit; P.X:=X; P.Y:=Y; P:=TPaintBox(Sender).ClientToScreen(P); TPaintBox(Sender).Left:=TPaintBox(Sender).Left+P.X-OldX;
TPaintBox(Sender).Top:=TPaintBox(Sender).Top+P.Y-OldY; OldX:=P.X;
OldY:=P.Y;
end;//结束移动
procedure TFormDoor.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
If Not(Sender Is TPaintBox) Then Exit;
If Not MDown Then Exit;
MDown:=False; If Sender<>CurrentItem Then Exit; TPaintBox(Sender).Left:=Round((TPaintBox(Sender).Left / 8))*8;
TPaintBox(Sender).Top:=Round((TPaintBox(Sender).Top / 8))*8; //保存位置信息
//显示信息
end;