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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值