在MouseDown的时候记下来鼠标的位置,然后在MouseMove的时候设置其Left和Top就可以了
OnMouseDown
begin
GetCursorPos(FPoint);//需要在Form的Private出声明该变量 FPoint: TPoint;
FMouseDowned := True;//需要在Form的Private出声明该变量 FMouseDowned: Boolean;
end;
OnMouseMove
var
P: TPoint;
begin
if FMouseDowned then
begin
GetCursorPos(P);
Label1.Top := Label1.Top + P.Y - FPoint.Y;
Label1.Left := Label1.Left + P.X - FPoint.X;
FPoint := P;
end;
end;
ONMOuseUp
begin
FMouseDown := False;
end;
OnMouseDown
begin
GetCursorPos(FPoint);//需要在Form的Private出声明该变量 FPoint: TPoint;
FMouseDowned := True;//需要在Form的Private出声明该变量 FMouseDowned: Boolean;
end;
OnMouseMove
var
P: TPoint;
begin
if FMouseDowned then
begin
GetCursorPos(P);
Label1.Top := Label1.Top + P.Y - FPoint.Y;
Label1.Left := Label1.Left + P.X - FPoint.X;
FPoint := P;
end;
end;
ONMOuseUp
begin
FMouseDown := False;
end;
解决方案 »
- 求助:使用SPCOMM控件时,初始设置的问题!!!在线等!
- 【07.14】fastreport求助
- 怎样用delphi把bmp图象从oracle数据库中读出来?
- 如何将XPbutton组件安装到DELPHI 2010里面
- 高手请进:TreeView在右键单击时的焦点转移问题
- 给我一个关于多线程的解决方案吧!
- 求教 用 BHO 自动切换代理 ???
- 数据表中性别是'1'或'2',能否从DBGrid中显示成'男'或'女'?
- 为什么我用assignprn(pfile,'LPT1'); 报错呢
- 请教!自定义函数怎么使用,加在程序哪里?
- 怎么使dbgrid里的列宽度可调但不能被整体拖动即和其他列交换位置
- 怎样知道当前可执行文件所在路径,即程序文件所在路径
begin
if Button = mbLeft then
begin
ReleaseCapture;
PanelShowTime.Perform(WM_SysCommand, c_nDragMove, 0);
end;
end;
cursor:=crDrag;OnMouseMove
if cursor=crDrag then
移动控件;OnMouseUp
cursor:=crDefault
begin
if Button = mbLeft then begin
ReleaseCapture;
TWinControl(Sender).Perform(WM_SysCommand, SC_MOVE + 1, 0);
end;
end;
http://www.csdn.net/expert/topic/360/360881.shtm
Shift: TShiftState; X, Y: Integer);
const SC_DragMove=$F012;
begin
ReleaseCapture;
(Sender as TWinControl).Perform(WM_SysCommand,SC_DragMove,0);
end;
其中的EDIT1是控件名,作相应的改动!
cursor:=crDrag;OnMouseMove if cursor=crDrag then
移动控件;OnMouseUp
cursor:=crDefault
cursor:=crDrag;OnMouseMove if cursor=crDrag then
移动控件;OnMouseUp
cursor:=crDefault
const
//---系统常量---
c_nDragMove = $F017; //移动控件消息procedure TFormMain.PanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
ReleaseCapture;
PanelShowTime.Perform(WM_SysCommand, c_nDragMove, 0);
end;
end;