Formの位置とサイズを記憶させる ここではFormの位置とサイズをレジストリに保存して次回起動した時にその位置とサイズを復元させます。 ■ポイント
■その他
■レジストリの保存場所
■ソースは下記のようになります。
procedure
TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var Reg : TRegistry; begin Reg := TRegistry.Create; //サブキー作成 Reg.CreateKey('PAPY'); Reg.OpenKey('PAPY',True); //Topを格納 Reg.WriteInteger('Top',Form1.Top); //Leftを格納 Reg.WriteInteger('Left',Form1.Left); //Widthを格納 Reg.WriteInteger('Width',Form1.Width); //Heightを格納 Reg.WriteInteger('Height',Form1.Height); Reg.CloseKey; Reg.Free; end;
program
Project1; uses Forms,Registry, Unit1 in 'Unit1.pas' {Form1}; {$R *.RES} var Reg : TRegistry; hData : Integer ; begin Application.Initialize; Application.CreateForm(TForm1, Form1); {レジストリの読み込み} /////////////////////////////////////////////////// Reg := TRegistry.Create; if Reg.OpenKey('PAPY',False ) then begin hData :=Reg.ReadInteger('Top'); Form1.Top :=hData; hData :=Reg.ReadInteger('Left'); Form1.Left :=hData; hData :=Reg.ReadInteger('Width'); Form1.Width :=hData; hData :=Reg.ReadInteger('Height'); Form1.Height :=hData; Reg.CloseKey ; end; Reg.Free; /////////////////////////////////////////////////// Application.Run;
end.