zoukankan      html  css  js  c++  java
  • 款式修改窗口,开发调整过窗口格局保存功能,关了窗口重新打开还是按关闭前的格局.

    1.
    如果允许用户在运行时移动控件和调整控件大小,你必须确保在窗体关闭时保存控件的位置,窗体创建/加载时恢复每个控件的位置。以下是如何在INI文件中存储的每个窗体上的控件的左,上,宽度和高度属性。

    接下来的两个程序TFrmStyleProp.WriteControlPlacement;
    var和TFrmStyleProp.ReadControlPlacement;用Delphi的ini文件来存储和恢复窗体上每一个控制的位置属性:
    //款式修改窗口格局 BN0158
    uiuujhbfggchchhchjhcjhjchj

    //写窗口的控制放置位置
    procedure TFrmStyleProp.WriteControlPlacement;
    var
    iniFile : TIniFile;
    idx : integer;
    ctrl : TControl;
    begin
    iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'-prop.ini')) ;
    try
    for idx := 0 to -1 + Self.ComponentCount do
    begin
    if Components[idx] is TRzSizePanel 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;
    end;
    finally
    FreeAndNil(iniFile) ;
    end;
    end;

    //读控制窗口的位置
    procedure TFrmStyleProp.ReadControlPlacement;
    var
    iniFile : TIniFile;
    idx : integer;
    ctrl : TControl;
    begin
    iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'-prop.ini')) ;
    try
    for idx := 0 to -1 + Self.ComponentCount do
    begin
    if Components[idx] is TRzSizePanel 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;
    end;
    finally
    FreeAndNil(iniFile) ;
    end;
    end; (*ReadControlPlacement*)

    2.procedure ReadControlPlacement;
    procedure WriteControlPlacement;


    3.procedure TFrmStyleProp.act_CloseStyleExecute(Sender: TObject);
    begin
    .........
    WriteControlPlacement
    end;


    4.//调用

    在窗口的FormShow事件处理函数中调用ReadControlPlacement;
    procedure TFrmStyleProp.FormShow(Sender: TObject);
    begin
    ReadControlPlacement;
    end;

    在窗口的FormClose事件处理函数中调用WriteControlPlacement;

    procedure TFrmStyleProp.FormClose(Sender: TObject;
    var Action: TCloseAction);
    begin
    WriteControlPlacement;
    Action := caFree;
    end;


    5.
    uses
    ..........
    ..........
    ..........
    IniFiles;

  • 相关阅读:
    June. 26th 2018, Week 26th. Tuesday
    June. 25th 2018, Week 26th. Monday
    June. 24th 2018, Week 26th. Sunday
    June. 23rd 2018, Week 25th. Saturday
    June. 22 2018, Week 25th. Friday
    June. 21 2018, Week 25th. Thursday
    June. 20 2018, Week 25th. Wednesday
    【2018.10.11 C与C++基础】C Preprocessor的功能及缺陷(草稿)
    June.19 2018, Week 25th Tuesday
    June 18. 2018, Week 25th. Monday
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/8819839.html
Copyright © 2011-2022 走看看