我在Form1之上置放了十个speedbutton按钮,在运行时如何实现自由拖动这些按钮并随意摆放,并即时保存各自位置,以便下次打开时是最新保存状态位置。
解决方案 »
- 如何将ReportMachine编译为ActiveX控件。
- 如何取计算机名称?在线等
- idUdpServer 接收不到数据
- 如何直接使用ADO(不使用Delphi的ADO组件)
- c/s结构数据中,怎么解决多人同时处理一字段所代来的并发问题呢,大家是怎么解决的呢
- memo中,怎么滚动到具体某一行,并得到焦点就在该行?
- delphi6.0和delphi7.0有什么区别?
- 有谁用过tesseract-ocr开源吗?
- 微软的这两天要查我公司,请各位大虾出下主意。送分
- P^.x:=100怎么实现?
- 请教高手帮忙TidHttp的问题!在线等待送分
- 哪位大哥经济学好,给讲一下人民币升值会在哪些方面给中国带来坏处?
你可以把这十个按钮赋值给一个数组,然后对改数组进行操作
With 数组 do
begin
OnMouseDown:=MyMouseDown;
OnMouseMove:=MyMouseMove;
OnMouseUp:=MyMouseUp;
end;
上面的函数需要自己编写。
Draging: Boolean;
DownX,DownY: Integer;
procedure TForm1.MyMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Draging := True;
DownX := X;
DownY := Y;
end;
procedure TForm1.MyMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if Draging then
begin
if Sender is TSpeedButton then
begin
(Sender as TSpeedButton).Left := X - DownX + (Sender as TSpeedButton).Left;
(Sender as TSpeedButton).Top := Y - DownY + (Sender as TSpeedButton).Top;
end;
end;
end;
procedure TForm1.MyMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Draging then
begin
Draging := False;
//将当前的控件位置存放到数据库中
end;
end;
Shift: TShiftState; X, Y: Integer);
begin
GetCursorPos(oldPT);
end;procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
pt: TPoint;
begin
GetCursorPos(pt);
if ssLeft in Shift then
begin
Button1.Left := Button1.Left + pt.X - oldPT.X;
Button1.Top := Button1.Top + pt.Y - oldPT.Y;
self.Refresh;
end;
oldPT := pt;
end;