不好意思,是我没有说清楚。运行时移动是指,运行时鼠标可以拖着label控件在窗体上到处走。 我现在用的是这样: procedure TForm1.Label1MouseDown begin dx:=x; dy:=y; end;procedure TForm1.Label1MouseMove begin if (ssleft in shift) then begin label1.Top:=Label1.Top+y-dy; label1.Left:=label1.Left+x-dx; end; end;而我想用的是: procedure TForm1.Label1MouseMove const SC_DRAGMOVE = $F012; begin ReleaseCapture; (Sender as TControl).Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0); end; 这条语句可以移动除label外的大多数控件,就是不能移动label,令我郁闷:(
Tinifiles类是用来操作ini文件的! 给你一例子!(保存颜色的)写 var inif:Tinifile; begin inif:=Tinifile.Create('E:\Colors.ini'); inif.WriteInteger('Option','FontColor',label1.font.color); end;读 var inif:Tinifile; begin inif:=Tinifile.Create('E:\Colors.ini'); label1.font.color:=inif.ReadInteger('Option','FontColor',clBlack);//clblack一定要加,不 end; //然颜色会改变
在 OnMouseMove 事件中,程序如下: var curPos: TPoint; begin // 得到当前鼠标的位置 GetCursorPos(curPos); curPos := Self.ScreenToClient(curPos); // 设置新的位置 with TWinControl(Sender) do SetBounds(curPos.x, curPos.y, Width, Height); end;不妨试试,效果肯定很好。
在 OnMouseMove 事件过程中,程序如下: var curPos: TPoint; begin // 当前鼠标位置 GetCursorPos(curPos); curPos := Self.ScreenToClient(curPos); // 设置位置 with TWinControl(Sender) do SetBounds(curPos.x, curPos.y, Width, Height); end;试试?
with TWinControl(Sender) do 改为: with TControl(Sender) do就行了,若还不行,只要:with TControl(Sender) do begin Left := curPos.x; Top := curPos.y; end;我用过,行的,不信就试试!
若还不行,只要做个判断即可。if Sender is TLabel then with TLabel(Sender) do begin Left := curPos.x; Top := curPos.y; end;
得改一下,还要判断鼠标按下的是左键:)不过,还是很感谢楼上的 procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var curPos: TPoint; begin GetCursorPos(curPos); curPos := Self.ScreenToClient(curPos); if (ssleft in shift) then with TLabel(Sender) do begin Left := curPos.x; Top := curPos.y; end; end;
用TStaticText代替TLabel即可解决问题。
彻底解决:彻底解决:彻底解决:彻底解决:彻底解决:彻底解决:In FormOnCreate,you add Label1.DragMode:= dmAutomatic In FormOnDragOver you add Label1.Top:=y; Label1.Left:=x;
彻底解决:彻底解决:彻底解决:彻底解决:彻底解决:彻底解决:In FormOnCreate,you add Label1.DragMode:= dmAutomatic In FormOnDragOver you add Label1.Top:=y; Label1.Left:=x;
~~~~
TINIFile是什么类,能给仔细点吗?
TINIFile是专门用来读写 *.ini文件的类,对INI文件操作进行了封装。
便于使用。具体方法查阅帮助吧。
Drate(小虫) 的意思是在退出时,对控件位置进行保存;下次运行时,读取位置,根据位置值进行设置。
label1.Top:=30;
指的就是通过修改属性达到移动的目的阿!
不保存到文件就保存到注册表罗,但我认为更繁!
我现在用的是这样:
procedure TForm1.Label1MouseDown
begin
dx:=x;
dy:=y;
end;procedure TForm1.Label1MouseMove
begin
if (ssleft in shift) then
begin
label1.Top:=Label1.Top+y-dy;
label1.Left:=label1.Left+x-dx;
end;
end;而我想用的是:
procedure TForm1.Label1MouseMove
const SC_DRAGMOVE = $F012;
begin
ReleaseCapture;
(Sender as TControl).Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;
这条语句可以移动除label外的大多数控件,就是不能移动label,令我郁闷:(
给你一例子!(保存颜色的)写
var
inif:Tinifile;
begin
inif:=Tinifile.Create('E:\Colors.ini');
inif.WriteInteger('Option','FontColor',label1.font.color);
end;读
var
inif:Tinifile;
begin
inif:=Tinifile.Create('E:\Colors.ini');
label1.font.color:=inif.ReadInteger('Option','FontColor',clBlack);//clblack一定要加,不
end; //然颜色会改变
var
curPos: TPoint;
begin
// 得到当前鼠标的位置
GetCursorPos(curPos);
curPos := Self.ScreenToClient(curPos); // 设置新的位置
with TWinControl(Sender) do
SetBounds(curPos.x, curPos.y, Width, Height);
end;不妨试试,效果肯定很好。
var
curPos: TPoint;
begin
// 当前鼠标位置
GetCursorPos(curPos);
curPos := Self.ScreenToClient(curPos); // 设置位置
with TWinControl(Sender) do
SetBounds(curPos.x, curPos.y, Width, Height);
end;试试?
改为:
with TControl(Sender) do就行了,若还不行,只要:with TControl(Sender) do
begin
Left := curPos.x;
Top := curPos.y;
end;我用过,行的,不信就试试!
with TLabel(Sender) do
begin
Left := curPos.x;
Top := curPos.y;
end;
procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
curPos: TPoint;
begin
GetCursorPos(curPos);
curPos := Self.ScreenToClient(curPos);
if (ssleft in shift) then
with TLabel(Sender) do
begin
Left := curPos.x;
Top := curPos.y;
end;
end;
Label1.DragMode:= dmAutomatic
In FormOnDragOver you add
Label1.Top:=y;
Label1.Left:=x;
Label1.DragMode:= dmAutomatic
In FormOnDragOver you add
Label1.Top:=y;
Label1.Left:=x;
TRegistry,TINIFile;