你是完全不会还是遇到什么问题了?
一般的做法是用SetCapture获得鼠标焦点,然后记录鼠标的位置,在OnMouseMove事件里计算鼠标的位移,然后在移动控件。我猜测你的问题可能是Label没有Handle,无法传递参数给SetCapture;建议你改用TStaticText,功能和Label一样,但是一个独立的窗体控件。如果非要用Label,你应该在Label的OnMouseDown事件里设置一个标志,在它的MouseMove或者父窗体的MouseMove里改变位置。
一般的做法是用SetCapture获得鼠标焦点,然后记录鼠标的位置,在OnMouseMove事件里计算鼠标的位移,然后在移动控件。我猜测你的问题可能是Label没有Handle,无法传递参数给SetCapture;建议你改用TStaticText,功能和Label一样,但是一个独立的窗体控件。如果非要用Label,你应该在Label的OnMouseDown事件里设置一个标志,在它的MouseMove或者父窗体的MouseMove里改变位置。
解决方案 »
- Delphi 资源文件无法嵌入大于48*48的图标文件
- delphi多层架构设想,说的都有分
- 关于宏的问题
- 【散分】近日受G级MAIL诱惑,重检Yahoo!Messenger,现诚征其上Delphi/c#战友,共同进步
- 请问,数据转换的问题
- 在图像上动态生成数据的问题,急!!!请大虾们帮忙呀。。
- 关于WritePrivateProfileString的问题,请指教!!!
- 如何将string型转换为Char型?
- (续几?不知道,1吧)刚才想散分,不过不能给超过100分。想开多个贴,结果只开了一个,然后荣誉分只有81分了……(10分钟后结贴)
- 连接Sybase
- 进程与线程
- just have a try please.......?
加一个全局变量POINT OldPoint;void __fastcall TForm1::Label1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
POINT pt;
GetCursorPos(&pt); if(Shift.Contains(ssLeft))
{
Label1->Left += pt.x - OldPoint.x;
Label1->Top += pt.y - OldPoint.y; OldPoint = pt;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
GetCursorPos(&OldPoint);
}
//---------------------------------------------------------------------------
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
xx: TPoint;
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
GetCursorPos(xx);
end;procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
yy: TPoint;
begin
GetCursorPos(yy); if ssLeft in Shift then
begin
Label1.Left := Label1.Left + yy.x - xx.x;
Label1.Top := Label1.Top + yy.y - xx.y;
xx := yy;
end;
end;end.
所以,先给大伙2分吧,期望有好的回答。
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbleft then
begin
ReleaseCapture;
Label.perfrom(WM_SYSCOMMAND,$F012,0);
END;
end;
Label1.perform(WM_SysCommand, $F012, 0);