打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
记忆Delphi窗体上控件的位置和大小

procedure TFormMain.WriteControlPlacement;
var
   iniFile : TIniFile;
   idx : integer;
   ctrl : TControl;
   listview:TListView;
   i:Integer;
begin
   iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini')) ;
   try
     for idx := 0 to -1 + Self.ComponentCount do
     begin
       if Components[idx] is TControl then
       begin
         ctrl := TControl(Components[idx]) ;
         iniFile.WriteInteger(ctrl.Name,'Top',ctrl.Top) ;
         iniFile.WriteInteger(ctrl.Name,'Left',ctrl.Left) ;
         iniFile.WriteInteger(ctrl.Name,'Width',ctrl.Width) ;
         iniFile.WriteInteger(ctrl.Name,'Height',ctrl.Height) ;
       end;
       if Components[idx] is TListView then
       begin
           listview:= Components[idx] as TListView ;
           //iniFile.WriteInteger(ctrl.Name,'ColumnCount',listview.Columns.Count) ;
           for I := 0 to listview.Columns.Count-1 do
           begin
               iniFile.WriteInteger(ctrl.Name,'ColWidth'+Inttostr(I),listview.Columns[i].Width) ;
           end;


       end;
     end;
   finally
     FreeAndNil(iniFile) ;
   end;
end; (*WriteControlPlacement*)


procedure TFormMain.ReadControlPlacement;
var
   iniFile : TIniFile;
   idx : integer;
   ctrl : TControl;
   listview:TListView;
   i:Integer;
begin
   iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini')) ;
   try
     for idx := 0 to -1 + Self.ComponentCount do
     begin
       if Components[idx] is TControl then
       begin
         ctrl := TControl(Components[idx]) ;
         ctrl.Top := iniFile.ReadInteger(ctrl.Name,'Top',ctrl.Top) ;
         ctrl.Left := iniFile.ReadInteger(ctrl.Name,'Left',ctrl.Left) ;
         ctrl.Width := iniFile.ReadInteger(ctrl.Name,'Width',ctrl.Width) ;
         ctrl.Height := iniFile.ReadInteger(ctrl.Name,'Height',ctrl.Height) ;
       end;
       if Components[idx] is TListView then
       begin
           listview:= Components[idx] as TListView ;
           //iniFile.WriteInteger(ctrl.Name,'ColumnCount',listview.Columns.Count) ;
           for I := 0 to listview.Columns.Count-1 do
           begin
              listview.Columns[i].Width:= iniFile.ReadInteger(ctrl.Name,'ColWidth'+Inttostr(I),100) ;
           end;
       end;

     end;
   finally
     FreeAndNil(iniFile) ;
   end;
end; (*ReadControlPlacement*)


//注:在窗体的OnCreate事件处理程序中调用ReadControlPlacement。
//在窗体的OnClose或OnDestroy事件处理程序中调用WriteControlPlacement。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi中当月第一天最后一天的函数等函数
Delphi TListview[3]实现拖拽功能
手把手带你深入了解ctrl键的使用
delphi入门点点滴滴 2001年底写的
delphi取得文件图标并在TListView中显示
VBA窗体之ListView控件的基本应用 | VBA实例教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服