运行状态拖动控件的问题

bluedelphi 2004-09-16 11:08:10
使用以下代码在某个控件的 onMouseDown 事件里,能实现运行状态拖动的效果
ReleaseCapture;
Sendmessage((Sender as TWinControl).Handle,WM_syscommand,$F012,0);
但我现在有个问题,当拖动停止的时候,怎么捕获鼠标放开了时候! 我需要在控件停止拖动的
时候处理一些东西,比例获得控件新的位置等之类的信息,请高手指定,应该怎么处理,要写什么样的
代码?
...全文
145 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluedelphi 2004-09-20
  • 打赏
  • 举报
回复
摆脱高手了,谁能指点一二啊
bluedelphi 2004-09-17
  • 打赏
  • 举报
回复
首先很感谢各位的关注
但是感觉你们的回答不是我想要的答案啊
OnMouseDown里面写了
ReleaseCapture;
Sendmessage(panel1.Handle,wm_syscommand,$F009,0);
后,onMouseUp 是不响应的啊! 里面写代码有什么用了!
fei19790920 2004-09-16
  • 打赏
  • 举报
回复
两种方法
1。
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
ReleaseCapture;
panel1.perform(WM_SysCommand, $F012, 0);

end;

2。

var
Form1: TForm1;
MoveEn:Boolean;
XY:TPoint;
implementation

{$R *.DFM}

procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button =mbLeft then
begin
MoveEn:=True;
XY.x :=x;
XY.y :=y;
end;
end;

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

end;

procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if MoveEn then
begin
Label1.Left :=Label1.Left +(x-XY.x);
Label1.Top :=Label1.Top +(y-XY.y);
end;

end;

jinjazz 2004-09-16
  • 打赏
  • 举报
回复
faq里有:原帖找不到了

//==============================================================================

//任意摆布一个控件(拖动、放大、缩小)******************************************

//==============================================================================

procedure ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer);//Precision:精度,该方法可以在onmousemove中调用

var SC_MANIPULATE: Word;

begin

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

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

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

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

then begin

SC_MANIPULATE := $F001;

WinControl.Cursor := crSizeWE;

end

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

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

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

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

then begin

SC_MANIPULATE := $F002;

WinControl.Cursor := crSizeWE;

end

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

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

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

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

then begin

SC_MANIPULATE := $F003;

WinControl.Cursor := crSizeNS;

end

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

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

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

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

then begin

SC_MANIPULATE := $F004;

WinControl.Cursor := crSizeNWSE;

end

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

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

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

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

then begin

SC_MANIPULATE := $F005;

WinControl.Cursor := crSizeNESW ;

end

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

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

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

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

then begin

SC_MANIPULATE := $F006;

WinControl.Cursor := crSizeNS;

end

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

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

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

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

then begin

SC_MANIPULATE := $F007;

WinControl.Cursor := crSizeNESW;

end

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

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

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

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

then begin

SC_MANIPULATE := $F008;

WinControl.Cursor := crSizeNWSE;

end

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

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

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

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

then begin

SC_MANIPULATE := $F009;

WinControl.Cursor := crSizeAll;

end

else begin

SC_MANIPULATE := $F000;

WinControl.Cursor := crDefault;

end;

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

if Shift=[ssLeft] then

begin

ReleaseCapture;

WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);

end;

end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin


ManipulateControl((Sender as TWinControl), Shift, X, Y, 10);

end;
fim 2004-09-16
  • 打赏
  • 举报
回复
MouseUp事件中写代码啊,当然最好设一下标志,这样比较好判断些

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FMoving :=True;
//....
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Fmoving := False;
//.....
end;
yingshis 2004-09-16
  • 打赏
  • 举报
回复
up
zdq801104 2004-09-16
  • 打赏
  • 举报
回复
学习

5,388

社区成员

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

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