private
{ Private declarations }
public
//设置全局变量
var
X, Y: Integer;
IsDrag: Boolean;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//创建时初始化参数
IsDrag:=False;
end;
//下面三个事件添加后即可,我是以TLabeledEdit为例子,你们可以修改下
procedure TForm1.LabeledEdit2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsDrag := True;
Self.X := X;
Self.Y := Y;
end;
procedure TForm1.LabeledEdit2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if IsDrag then
begin
TLabeledEdit(Sender).Left := TLabeledEdit(Sender).Left + (X - Self.X);
TLabeledEdit(Sender).Top := TLabeledEdit(Sender).Top + (Y - Self.Y);
end;
end;
procedure TForm1.LabeledEdit2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsDrag := False;
end;
04-12
1070
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)