如何实现拖动label

soulhuman 2005-10-11 05:09:13
请问如何实现拖动一个label组件
...全文
232 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengxinwen 2006-05-22
  • 打赏
  • 举报
回复
哪能找到详细介绍windows消息的资料
mylovelypig 2006-05-22
  • 打赏
  • 举报
回复
用panel替代label,然后在panel的mousedown事件里

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
panel1.Perform(wm_syscommand,$f012,0)
end;

==========================================
这段代码,我查到处都有人贴,甚至象你这样的星级用户.

这段代码能否响应Panel的单击事件吗?
如果是BUTTON呢?用了这个代码,那么BUTTON的单击事件不是废了吗?







sjchao 2005-10-12
  • 打赏
  • 举报
回复
学习啊
xixuemao 2005-10-12
  • 打赏
  • 举报
回复
用panel替代label,然后在panel的mousedown事件里

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
panel1.Perform(wm_syscommand,$f012,0)
end;
wdswcy 2005-10-12
  • 打赏
  • 举报
回复
// 任意摆布一个控件 ( 拖动、放大、缩小 )******************************************
procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer);

var SC_MANIPULATE: Word;

begin

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的最左侧 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if (X<=Precision) and (Y>Precision) and (Y<Control.Height-Precision)

then begin

SC_MANIPULATE := $F001;

Control.Cursor := crSizeWE;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的最右侧 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>=Control.Width-Precision) and (Y>Precision) and (Y<Control.Height-Precision)

then begin

SC_MANIPULATE := $F002;

Control.Cursor := crSizeWE;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的最上侧 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>Precision) and (X<Control.Width-Precision) and (Y<=Precision)

then begin

SC_MANIPULATE := $F003;

Control.Cursor := crSizeNS;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的左上角 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X<=Precision) and (Y<=Precision)

then begin

SC_MANIPULATE := $F004;

Control.Cursor := crSizeNWSE;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的右上角 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>=Control.Width-Precision) and (Y<=Precision)

then begin

SC_MANIPULATE := $F005;

Control.Cursor := crSizeNESW ;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的最下侧 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>Precision) and (X<Control.Width-Precision) and (Y>=Control.Height-Precision)

then begin

SC_MANIPULATE := $F006;

Control.Cursor := crSizeNS;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的左下角 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X<=Precision) and (Y>=Control.Height-Precision)

then begin

SC_MANIPULATE := $F007;

Control.Cursor := crSizeNESW;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的右下角 **********************************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>=Control.Width-Precision) and (Y>=Control.Height-Precision)

then begin

SC_MANIPULATE := $F008;

Control.Cursor := crSizeNWSE;

end

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// 光标在控件的客户区 ( 移动整个控件 )******************************************

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

else if (X>5) and (Y>5) and (X<Control.Width-5) and (Y<Control.Height-5)

then begin

SC_MANIPULATE := $F009;

Control.Cursor := crSizeAll;

end

else begin

SC_MANIPULATE := $F000;

Control.Cursor := crDefault;

end;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if Shift=[ssLeft] then

begin

ReleaseCapture;

Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);

end;

end;
hellolongbin 2005-10-12
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
x1,y1:integer;
ondrag:boolean;
implementation

{$R *.dfm}

procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Shift=[ssLeft] then
begin
X1:=X;
Y1:=Y;
onDrag:=true;
end;
end;

procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
OnDrag:=false;
end;

procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if OnDrag then
begin
Label1.Left:=Label1.left +X-X1;
Label1.Top:=Label1.Top+Y-Y1;
end;
end;

end.

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧