delphi 程序运行时移动控件
程序在運行時用戶需要對一些控件進行重新移動布局,下次進入界面時顯示布局后的
方法1:每移動控件時就把位置寫入INI文件中
只需在控件的OnMouseDown事件寫如下代碼:
procedure TFMain.SpeedButton4MouseDown(Sender: TObject;
? Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const sc_move = $F011;
var
? SysFile: TiniFile;
begin
??? releasecapture;
??? TSpeedButton(sender).Perform(wm_syscommand, sc_move, 0);
??? try
????? SysFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Sys.ini');
????? sysFile.WriteInteger(TSpeedButton(sender).Name, 'TOP', TSpeedButton(sender).Top);
????? sysFile.WriteInteger(TSpeedButton(sender).Name, 'Left', TSpeedButton(sender).Left);
??? finally
????? SysFile.Free;
??? end;
end;
方法2:
?封裝一函數用于實現控件移動,在控件的OnMouseDown事件中調用即可,然后在關閉時遍利所有控件把位置寫入INI
procedure MoveControl(Control: TControl; Shift: TShiftState; X, Y, Prec: integer);
begin???
?? ?if Shift=[ssLeft] then
begin
ReleaseCapture;
Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
?end;
?//關閉寫入
? SysFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Sys.ini');
? Try
??? ?for i := 0 to ComponentCount - 1 do
???? begin
??????????sysFile.WriteString(TControl(Components[i]).Name ,TOP,TControl(Components[i]).TOP );
????????? sysFile.WriteString(TControl(Components[i]).Name ,Left,TControl(Components[i]).Left );
??? ??end;
???finally
????? SysFile.Free;
???end;
?
?
?
轉載于:https://www.cnblogs.com/liaobotao/archive/2012/05/31/2529221.html
總結
以上是生活随笔為你收集整理的delphi 程序运行时移动控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ANDROID内核和驱动篇-ANDROI
- 下一篇: 各种资源思科、gns3……